error:Index exceeds matrix dimensions.

3 ビュー (過去 30 日間)
Rachel Baumgarten
Rachel Baumgarten 2015 年 2 月 26 日
コメント済み: Stephen23 2015 年 2 月 27 日
Hello, I am trying to understand the problem here. The error is in (line 51) which is the one I have on either end. I cannot seem to figure it out. Any ideas?
%This begins the force analysis
for turn=['a','b','c','d','e','f','g']
r.(turn).r3=.331;
r.(turn).force=r.(turn).force(:,2);
r.(turn).v=length(r.(turn).force);
r.(turn).justtime=r.(turn).justtime(1:r.(turn).v);
r.(turn).justangle=r.(turn).justangle(1:r.(turn).v);
r.(turn).sinangle=sin(r.(turn).justangle);
r.(turn).nettorque=(r.(turn).r3)*(r.(turn).sinangle).*(r.(turn).force);
for b=1:(r.(turn).v);
* *r.(turn).deltatorque(b)=r.(turn).nettorque(b+1)-r.(turn).nettorque(b);* *
end
r.(turn).deltatorque=r.(turn).deltatorque.';
r.(turn).network=(r.(turn).nettorque(1:r.(turn).v)).*(r.(turn).deltatheta(1:r.(turn).v));
r.(turn).deltapotential=(r.(turn).nettorque).*(r.(turn).justangle);
r.(turn).gravity=(9.81*(r.(turn).m))*(r.(turn).deltatheta);
r.(turn).withoutgravity=(r.(turn).deltapotential(1:r.(turn).v))-(r.(turn).gravity(1:r.(turn).v));
r.(turn).totalwork=sum(r.(turn).withoutgravity);
fprintf('The Total Work is %f\n',r.(turn).totalwork)
end
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 2 月 27 日
Rachel - what is line 51 in the above code? Please attach your function rather than just copying and pasting part of the code. Unless it is the line
r.(turn).deltatorque(b)=r.(turn).nettorque(b+1)-r.(turn).nettorque(b);*
If the above line is causing the problem then do the following: before running your function type the following in the command window
dbstop if error
Now run your code and when the above error occurs, the MATLAB debugger will pause at the line that is causing the problem. When this happens, look at the variables - what is b, what is the length of r.(turn).nettorque(b+1), etc. Evaluate each piece of this line and check to see where the code is failing.
Stephen23
Stephen23 2015 年 2 月 27 日
Please upload the whole code using the paperclip button, then we can check this properly.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Microsoft .NET についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by