Index exceeds matrix dimensions help
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Toby Trett
am 15 Mär. 2018
Kommentiert: Rena Berman
am 19 Mär. 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 Kommentare
Jan
am 15 Mär. 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.
Akzeptierte Antwort
KL
am 15 Mär. 2018
Bearbeitet: KL
am 15 Mär. 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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!