Index exceeds matrix dimensions help
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2018-3-15
@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.
采纳的回答
KL
2018-3-15
编辑:KL
2018-3-15
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!