Index exceeds matrix dimensions help

1 回表示 (過去 30 日間)
Toby Trett
Toby Trett 2018 年 3 月 15 日
コメント済み: Rena Berman 2018 年 3 月 19 日
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
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.
Rena Berman
Rena Berman 2018 年 3 月 19 日
(Answers Dev) Restored edit

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

採用された回答

KL
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by