- 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.
What character can designate a specific frame in Matlab?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Saurabh Gupta
am 18 Aug. 2017
I don't really understand your question, but I see a couple of issues with your code:
Antworten (2)
Harsha Phadke
am 18 Aug. 2017
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
0 Kommentare
Image Analyst
am 18 Aug. 2017
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!