error:Index exceeds matrix dimensions.

3 vues (au cours des 30 derniers jours)
Rachel Baumgarten
Rachel Baumgarten le 26 Fév 2015
Commenté : Stephen23 le 27 Fév 2015
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 commentaires
Geoff Hayes
Geoff Hayes le 27 Fév 2015
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 le 27 Fév 2015
Please upload the whole code using the paperclip button, then we can check this properly.

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by