What character can designate a specific frame in Matlab?

조회 수: 2 (최근 30일)
Samuel Halle
Samuel Halle 2017년 8월 16일
답변: Image Analyst 2017년 8월 18일
Hello,
I am trying to write a code to find the instantaneous velocity of an object at every frame for a recording I have done. In order to do so I need to be able to tell matlab to take the displacement of an object at a specific frame(x) and to compare it to the frames immediately before and after that frame(X+1) and (X-1). The code I have written should function if I knew the correct character to represent a frame.
The code I have written is as follows:
startframe = 1; %Start Point%
endframe = length(L4_Ydata); %End Point%
frame = startframe; %Current%
while frame<=endframe
L4_Velocity_Vertical=(L4_Ydata(frame+1)-L4_Ydata(frame-1))/(2*(1/100));
end
I know that "frame+1" and "frame-1" are not the right terms. What I am trying to say is that frame+1 is the L4_Ydata at the frame immediately after a certain frame and that frame-1 is the L4_Ydata at the frame right before it. I need to do this for every frame. If anyone could help me do figure this out it would be much appreciated. I am having the same problem in other codes I am trying to write as well.
  댓글 수: 1
Saurabh Gupta
Saurabh Gupta 2017년 8월 18일
I don't really understand your question, but I see a couple of issues with your code:
  • You are not updating the value of "frame" in the loop, so its essentially an infinite loop.
  • Assuming you missed posting the the statement that updates "frame", you are not taking care of boundary conditions, i.e. when frame=1, frame-1=0 and L4_Ydata(frame-1) is invalid; and when frame=endframe, frame+1 exceeds the length of the vector and L4_Ydata(frame+1) is invalid.

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

답변 (2개)

Harsha Phadke
Harsha Phadke 2017년 8월 18일
The question is not entirely clear to me, but from what I understand about your implementation, if your data is actually a video, you could take a look at the videoreader and mmfileinfo functions from MATLAB which could be useful.
If instead its a 3 dimensional matrix, then the frame number would be represented by the third dimension of the matrix. In this case you can look at accessing data in multidimensional array on the following webpage: https://www.mathworks.com/help/matlab/math/multidimensional-arrays.html

Image Analyst
Image Analyst 2017년 8월 18일
You need to increment frame counter
while frame<=endframe
L4_Velocity_Vertical=(L4_Ydata(frame+1)-L4_Ydata(frame-1))/(2*(1/100));
frame = frame + 1;
end

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by