Retracting the time-tags from the histcounts
Show older comments
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
thresh = 5;
z = max(y, thresh)
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
8 Comments
Manoj Kumar V
on 15 Feb 2024
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
type tagtime_remaining.txt
Manoj Kumar V
on 16 Feb 2024
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)
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)
Dyuman Joshi
on 17 Feb 2024
Edited: Dyuman Joshi
on 17 Feb 2024
Manoj Kumar V
on 17 Feb 2024
Dyuman Joshi
on 17 Feb 2024
That is what I have done here - https://in.mathworks.com/matlabcentral/answers/2082553-retracting-the-time-tags-from-the-histcounts#comment_3067268
Did you not check my comment?
Manoj Kumar V
on 17 Feb 2024
Image Analyst
on 15 Feb 2024
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
Manoj Kumar V
on 15 Feb 2024
Moved: Dyuman Joshi
on 15 Feb 2024
Alexander
on 15 Feb 2024
Moved: Dyuman Joshi
on 15 Feb 2024
Could you supply the data and code for your picture above?
Manoj Kumar V
on 15 Feb 2024
Moved: Dyuman Joshi
on 15 Feb 2024
Categories
Find more on Time Series Events in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

