Retracting the time-tags from the histcounts

A histogram (number of time-tags per unit bin) was created using "histcoounts" for a series of time-tags (first picture). After creating histogram, I put the threshold (300) on the count such that the values below the 300 shall get deleted. And the time-tags should be retractable for those values that were above the threshold. Could you please help me with getrting the values of time-tags from the second picture?

1 Comment

You can use the max() function -
y = 1:10
y = 1×10
1 2 3 4 5 6 7 8 9 10
thresh = 5;
z = max(y, thresh)
z = 1×10
5 5 5 5 5 6 7 8 9 10

Sign in to comment.

Answers (2)

If you are working with R2019a or a later version, use readmatrix and writematrix. Otherwise, use writetable
D=readmatrix('timetags.txt');
%transposing as histcounts() returns a row vector
D1=histcounts(D, 'NumBins', 200).';
subplot(2,1,1);
plot(D1)
subplot(2,1,2);
D2=D1;
D2(D2<300)=[];
plot(D2)
%write data to a text file
writematrix(D2, 'tagtime.txt')
%check the contents of the file
type tagtime.txt
305 381 588 675 498 505 437 574 427 443 831 444 1134 418 406 376 337 366 383 369 602 1053 337 338 377 417 384 343 388 321 325 363 359 446 1088 397 300 304 333 566 524 438 387 432 355 1067 306 604 673 509 519 469 448 329 1027 855 325 896 712 733 354 331 408 578 786 640 311 307

8 Comments

Thank You. I see the data value is generated from your code. But, I need to ectract the time-tags values of remaining values.
In that case -
D=readmatrix('timetags.txt');
%transposing as histcounts() returns a row vector
D1=histcounts(D, 'NumBins', 200).';
subplot(2,1,1);
plot(D1)
subplot(2,1,2);
idx = D1>300;
D2 = D1(idx);
plot(D2)
%write data to a text file
writematrix(D2, 'tagtime_extracted.txt')
%Remaining vales
D3 = D1(~idx);
writematrix(D3, 'tagtime_remaining.txt')
%check the contents of the file
type tagtime_extracted.txt
305 381 588 675 498 505 437 574 427 443 831 444 1134 418 406 376 337 366 383 369 602 1053 337 338 377 417 384 343 388 321 325 363 359 446 1088 397 304 333 566 524 438 387 432 355 1067 306 604 673 509 519 469 448 329 1027 855 325 896 712 733 354 331 408 578 786 640 311 307
type tagtime_remaining.txt
279 215 193 187 266 213 188 170 215 177 283 179 202 216 253 260 116 209 261 197 153 174 230 142 223 166 221 231 165 136 154 159 120 180 152 135 201 202 151 156 208 208 231 250 154 220 211 276 209 221 300 280 229 224 223 251 277 283 220 236 229 259 286 248 214 253 223 253 295 195 182 151 183 186 158 194 235 167 154 191 231 285 192 163 173 126 157 141 150 177 252 245 245 217 242 169 242 202 244 236 254 281 290 270 221 235 213 238 226 152 187 265 281 229 223 155 157 159 231 261 275 195 149 214 199 192 161 210 240 281 248 231 240
Hi, Plot due to histcounts is created from 62110 timetags cells. After removing the values below the threshold, remaining timetags cells are 33961. I would like to read out all these 33961 timetags.
Okay, you want the corresponding original data. Check this -
D=readmatrix('timetags.txt');
%Get the bin counts and the bin indices of the data
[D1,~,k]=histcounts(D, 'NumBins', 200)
D1 = 1×200
305 381 588 675 498 505 437 574 427 443 831 444 1134 418 406 376 337 366 383 369 602 1053 337 338 377 417 384 343 388 279
k = 62110×1
1 1 1 1 1 1 1 1 1 1
subplot(2,1,1);
plot(D1)
subplot(2,1,2);
%Indices of bin counts with value greater than 300
idx = find(D1>300);
D2 = D1(idx);
plot(D2)
%Compare the indices to index of each element of original data
z = ismember(k, idx);
out_extracted = D(z)
out_extracted = 33961×1
1.0e+13 * 1.4248 1.4248 1.4248 1.4248 1.4248 1.4248 1.4248 1.4248 1.4248 1.4248
Use writematrix to save the extracted data as I have shown above.
Any updates @Manoj Kumar V?
I am yet to solve this question. In brief, my question is, I would like to see all those time-tags at the output which are not being deleted from the histcounts.
Yes. I could not find the timetags values as output.

Sign in to comment.

Try setting those counts to nan. Then they won't show up. Something like
data = 5000 * rand(1, 5000);
subplot(1, 2, 1);
[counts, binEdges] = histcounts(data);
plot(binEdges(1:end-1), counts, 'b-')
yline(300, 'r-')
counts(counts <= 300) = nan;
subplot(1, 2, 2)
plot(binEdges(1:end-1), counts)
grid on;

3 Comments

Thank you for the answer. I would like to elaborate my question.
Attached text document contains the timetags data. I prefer to create histogram of 200 bins of the time-tags. and remove the values below 300 (on y-axis) from the histogram. And then I want to get the time-tags values back of the un-deleted values in a text file. How can I do that?
Could you supply the data and code for your picture above?
Data (in txt format) and matlab code are attached below.

Sign in to comment.

Asked:

on 15 Feb 2024

Commented:

on 17 Feb 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!