Please help: calculate average frequency of histogram

조회 수: 1 (최근 30일)
llrb
llrb 2014년 5월 25일
댓글: Andrei Bobrov 2014년 5월 25일
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
George Papazafeiropoulos
George Papazafeiropoulos 2014년 5월 25일
Could you write down the calculation you want to make in detail?

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 5월 25일
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
llrb
llrb 2014년 5월 25일
Hi Andrei,
Thank you very much. I was trying to use accumarray function as well but kinda stuck there. My function was "c=accumarray(b,Sp,[],@...)"
Would you mind to explain what does @(x){x} means? or maybe there's a link of fun index that i can use in the future? thanks
Andrei Bobrov
Andrei Bobrov 2014년 5월 25일
Please read about function accumarray

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by