Index exceeds matrix dimensions

2 visualizzazioni (ultimi 30 giorni)
Andrew Wentz
Andrew Wentz il 12 Feb 2018
Commentato: Star Strider il 12 Feb 2018
I've compared my script to my classmates and have it exactly the same, yet I keep getting an error code and she is not.
The script:
shoxdata = filtdata(:, strmatch('RSHO_X', labels));
shoydata = filtdata(:, strmatch('RSHO_Y', labels));
hipxdata = filtdata(:, strmatch('RGT_X', labels));
hipydata = filtdata(:, strmatch('RGT_Y', labels));
knexdata = filtdata(:, strmatch('RKNE_X', labels));
kneydata = filtdata(:, strmatch('RKNE_Y', labels));
ankxdata = filtdata(:, strmatch('RANK_X', labels));
ankydata = filtdata(:, strmatch('RANK_Y', labels));
heexdata = filtdata(:, strmatch('RHEE_X', labels));
heeydata = filtdata(:, strmatch('RHEE_Y', labels));
metxdata = filtdata(:, strmatch('RMET_X', labels));
metydata = filtdata(:, strmatch('RMET_Y', labels));
hipangle = [];
kneeangle = [];
ankangle = [];
startframe = 1;
endframe = length(shoxdata);
frame = startframe;
while frame <= endframe
footseg = 180 + atand((heeydata(frame)-metydata(frame))/(heexdata(frame)-metxdata(frame)));
trunkseg = atan2d((shoydata(frame)-hipydata(frame)),(shoxdata(frame)-hipxdata(frame)));
thighseg = atan2d((hipydata(frame)-kneydata(frame)),(hipxdata(frame)-knexdata(frame)));
shankseg=atan2d((kneydata(frame)-ankydata(frame)),(knexdata(frame)-ankxdata(frame)));
hipangle = [hipangle:(thighseg-trunkseg)];
kneeangle = [kneeangle:(thighseg-shankseg)];
ankangle = [ankangle:(footseg-shankseg-90)];
frame = frame+1;
end
figure(1)
subplot(3,1,1)
plot(hipangle(151:265))
ylabel('Hip Angle')
subplot(3,1,2)
plot(kneeangle(151:265))
ylabel('Knee Angle')
subplot(3,1,3)
plot(ankangle(151:265))
ylabel('Ankle Angle')
  1 Commento
Star Strider
Star Strider il 12 Feb 2018
In the future, please format your code by highlighting it, then using the [{}Code] button to format it.

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 12 Feb 2018
If her code runs and yours doesn’t, yours and hers aren’t the same.
I suspect the problem may be here:
hipangle = [hipangle:(thighseg-trunkseg)];
kneeangle = [kneeangle:(thighseg-shankseg)];
ankangle = [ankangle:(footseg-shankseg-90)];
The colon (link) operator by default creates an ascending series with a default increment of 1. If the calculations in parentheses are less than ‘hipangle’, ‘kneeangle’, or ‘ankangle’ on the right-hand-side in the three assignments, the result will be an empty element. So first, check the sizes of those variables. I believe the problem will be readily apparent. That would throw the error in your plot calls.
This may be what you want to do:
hipangle = [hipangle (thighseg-trunkseg)];
kneeangle = [kneeangle (thighseg-shankseg)];
ankangle = [ankangle (footseg-shankseg-90)];
Here, I replaced the colon (:) with spaces (although commas (,) would work as well). See if that works in your code.
  2 Commenti
Andrew Wentz
Andrew Wentz il 12 Feb 2018
That worked!! Thank you so much!
Star Strider
Star Strider il 12 Feb 2018
As always, my pleasure!
If my Answer helped you solve your problem, please Accept it!

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by