interp1 and Index exceeds the number of array elements (0)
Show older comments
Hello,
Would you please assist me with the following program
for i=1:length(T_HCRM)-2
for j=1:phaz
comX1(i,:)=interp1([1:length(comXS(T_HCRM(i):T_TORM(i)))],comXS(T_HCRM(i):T_TORM(i)),[1:(length(comXS(T_HCRM(i):T_TORM(i)))-1)/(phaz-1):length(comXS(T_HCRM(i):T_TORM(i)))],'cubic');
end
end
I always receive this error message: Index exceeds the number of array elements (0). Error in interp1 (line 153) extrapMask = Xq < X(1) | Xq > X(end);
The mentioned lines are part of a program and has to normalize comXS which is a matrix of one column and 1911 rows to equal sections of 100 frames. Somebody else who is not available provided the program on a database for students but everybody has to change it according to his project.
As I understood from help of MATLAB, the 3 parts of the interp1 function (I mean parts separated by commas) have to have the same lengths. While the first two parts of the interp1 function (parts before the 1st ( length(comXS(T_HCRM(i):T_TORM(i))) ) and the 2nd comma (comXS(T_HCRM(i):T_TORM(i)) )) have equal length AND different part of the 3rd part have equal length, I do not understand why the total length of the 3rd part is 532! I mean length of length (comXS(T_HCRM(i):T_TORM(i))) is 537 and length of comXS(T_HCRM(i):T_TORM(i)) is 537. These parts agait are used in the 3rd part (part located between 2nd comma and 3rd comma). But surprizingly, total length of the 3rd part " length(comXS(T_HCRM(i):T_TORM(i)))-1)/(phaz-1):length(comXS(T_HCRM(i):T_TORM(i))) ".
As you are professionals, maybe the way that I asked you my question is not the best way, but believe me, after spending several hours to find a solution, I am really confused and frustrated with this issue. I hope your knowledge and experience assist me. I am a beginner.
Thank you so much,
Accepted Answer
More Answers (1)
Vahid Esmaeili
on 20 Jul 2020
Edited: Vahid Esmaeili
on 20 Jul 2020
5 Comments
Walter Roberson
on 20 Jul 2020
Your original code had a bunch of places that relied upon
T_HCRM(i):T_TORM(i)
When the order of the markers is reversed from the typical low-speed version (whether due to measurement error or due to unusual gaits) then the result would be an empty vector, and your calculation messes up in that situation.
What should be done in the calculation at the point? For example should the two locations just be exchanged, or should the calculation become different?
Is it possible for one of the parts to be absent some of the time? For example someone on crutches hopping occasionally? If so then what should be done?
I am not clear on what the rules are for where to place the red and green arrows. It does not look to me as if the rule is about local minima or local maxima: it looks to me as if the rule might be that one of them is at the point where the curvature decreases substantially (from steep negative to either positive or much less negative), and that the other one of them is at the point where the curvature starts increasing substantially (from near-ish zero to steep positive.) This is not the same rule as local minima: you had locations that were similar to
\ /
\ /
< >
----v-
the local min would be at the bottom of the v, but the place the curvature starts changing rapidly would be the location after that.
Vahid Esmaeili
on 20 Jul 2020
Edited: Vahid Esmaeili
on 20 Jul 2020
Vahid Esmaeili
on 20 Jul 2020
Edited: Vahid Esmaeili
on 20 Jul 2020
Walter Roberson
on 20 Jul 2020
This has gotten too complicated for me. I am working on a lot of different things at the same time, and it would take a lot of analysis for me to figure out what the above explanations mean in practice.
I see why fuzzy logic gait classification has been used by a number of people...
I would consider something like a Finite State Machine that instead of examining indefinitely into the future, has state about current hypotheses of what is happening, and state about predictions of where the feet will go next, and at each step receives one reading from each of the two sensors, and uses the information to change state or refine the predictions about where the feet will go next.
Vahid Esmaeili
on 21 Jul 2020
Categories
Find more on National Instruments Frame Grabbers 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!