Please help create a transition matrix

조회 수: 22 (최근 30일)
llrb
llrb 2014년 5월 20일
댓글: shahab anjum 2020년 3월 9일
Hi,
I hope anyone could help me, I'm kinda new to Matlab.
I have a variable 'velocity' with the value ranging from 0-48 km/hr. I have about 2250 of these data. I would like to create a frequency matrix of the speed transition follows another speed.
Velocity :
1.28
0.57
0.75
2.88
8.05
13.7
...
I would like to make a frequency matrix with this criteria:
Explanation: cell [2,2] --> velocity < 2 is followed by velocity < 2 one time.
I really appreciate any help you give. Thank you for your time.
Best,
Ella

채택된 답변

Sven
Sven 2014년 5월 20일
Hi Ella,
The code below should do what you're looking for. I displayed the result as an image but you can just look at the final contents of freqMat
velocity = [1.28 0.57 0.75 2.88 8.05 13.7]
binEdges = 0:2:20; % 0 to 2 is the first bin, 2 to 4 is second bin, etc
[~,velBinNos] = histc(velocity,binEdges); % Histc just asks which bin each velocity belongs to
binTicks = binEdges(1:end-1); % Don't need the last bin edge
freqMat = zeros(length(binTicks));
fromBinNos = velBinNos(1:end-1);
nextBinNos = velBinNos(2:end);
for i = 1:length(fromBinNos)
freqMat(fromBinNos(i),nextBinNos(i)) = freqMat(fromBinNos(i),nextBinNos(i)) + 1;
end
figure, imagesc(binTicks,binTicks,freqMat)
xlabel 'Next velocity bin'
ylabel 'First velocity bin'
colorbar
Did this help you out?
Thanks, Sven.
  댓글 수: 3
llrb
llrb 2014년 5월 21일
Hi Sven,
I have a question about the code. Could you pls explain why we don't need the last bin edge for this: binTicks = binEdges(1:end-1)?
thanks, Ella
shahab anjum
shahab anjum 2020년 3월 9일
can you help me to please to build transition matrix if i have 1000x286 matrix.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by