Index exceeds matrix dimensions

조회 수: 10 (최근 30일)
Andrew Wentz
Andrew Wentz 2018년 2월 12일
댓글: Star Strider 2018년 2월 12일
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
Star Strider
Star Strider 2018년 2월 12일
In the future, please format your code by highlighting it, then using the [{}Code] button to format it.

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

답변 (1개)

Star Strider
Star Strider 2018년 2월 12일
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
Andrew Wentz
Andrew Wentz 2018년 2월 12일
That worked!! Thank you so much!
Star Strider
Star Strider 2018년 2월 12일
As always, my pleasure!
If my Answer helped you solve your problem, please Accept it!

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by