Index exceeds matrix dimensions help

1 visualizzazione (ultimi 30 giorni)
Toby Trett
Toby Trett il 15 Mar 2018
Commentato: Rena Berman il 19 Mar 2018
I am writing a script for determining the displacement and velocity of an arm on a complex slider system relative to the angle of rotation of the first slider. I am trying to plot the displacement and velocity on the same graph, to a precision of 0.001rad intervals. Displacement is working perfectly, but my velocity array is coming up as "Index exceeds matrix dimensions" which I cannot figure out given I have used the same size array to store the output values.
I have also played around with making the array much larger but still get the same message.
Code attached, error "Index exceeds matrix dimensions" in line 43 "Yv=(y(n+1)-(y(n)))/0.0005;"
Thanks for any help
  2 Commenti
Jan
Jan il 15 Mar 2018
@Toby: Please revert your question. It is very impolite to remove the question after somebody has spent the time for posting an answer. Now KL's work is orphaned and the readers of the forum cannot profit from it anymore.
Rena Berman
Rena Berman il 19 Mar 2018
(Answers Dev) Restored edit

Accedi per commentare.

Risposta accettata

KL
KL il 15 Mar 2018
Modificato: KL il 15 Mar 2018
There are so many issues. Let's address your error first. Your counter variable n is bigger than the size of your y vector (on this line, Yv=(y(n+1)-(y(n)))/0.0005;). Hence you get the error.
Nevertheless you don't really calculate velocity. You simply initialize v vector with zeros and and trying to calculate only one element (because m is just 1 and you don't have a loop to calculate the other elements).
If you want to carry out your calculations with a loop (Matlab is much more powerful, no loops are needed for your problem though), simply use one loop with a counter variable like below.
your constants here
Theta=0:0.001:(2*pi);
numOfElements = numel(Theta);
y = zeros(1,numOfElements);
v = zeros(1,numOfElements);
for count = 1:numOfElements
y(count) = something like a*theta(count)*bla*blabla
v(count) = something else
end

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by