Please help: calculate average frequency of histogram
1 view (last 30 days)
Show older comments
Hello everyone,
I hope anyone could help me, I'm kinda new to Matlab.
I have two variables, speed and time. I would like to calculate mean duration of each speed interval.
For example:
In Speed interval between 2-4 mph (shown in yellow color), i have 4 speed data. The first data was last for 1-sec only, and the others were last for 3 sec. The mean duration of speed stability is 2 sec.
I really appreciate any help you give.
Thank you for your time.
1 Comment
George Papazafeiropoulos
on 25 May 2014
Could you write down the calculation you want to make in detail?
Accepted Answer
Andrei Bobrov
on 25 May 2014
Sp=[3 9 1 2 3 2.5 7.8 6.5 9.3 9.1]';
[n,b] = histc(Sp,0:2:10);
c = accumarray(b,(1:numel(Sp))',[],@(x){x});
ii = cellfun(@(z)numel(unique(diff(sort(z)))),c);
ii(~ii) = 1;
out = n(1:end-1)./ii;
2 Comments
More Answers (0)
See Also
Categories
Find more on Histograms 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!