Index exceeds matrix dimensions error

for i=1:6
w(1)=w_o;
Vmean(i) = sqrt ((w(i)-V*sind(alpha))^2 + (V*cosd(alpha))^2);
w(i) = T / (2*rho*A*Vmean(i))
end
Hey, i'm trying to do an iterative process with the 2 equations above until my w value converges, when using this for loop, i keep getting an "index exceeds matrix dimensions" error when i try and run it. would appreciate some help, and maybe some tips on maybe a better way to do the iteration, because ideally i think a while loop would be better but i didn't know how to go about it. Thanks in advance.

回答 (2 件)

James Tursa
James Tursa 2018 年 5 月 29 日
編集済み: James Tursa 2018 年 5 月 29 日

0 投票

You can get this error if numel(w)<6, so I would check that first.
the cyclist
the cyclist 2018 年 5 月 29 日
編集済み: the cyclist 2018 年 5 月 29 日

0 投票

I am guessing that the variable w does not exist until you create it using the line
w(1)=w_o;
Therefore, w is a vector with one element.
On the second pass through that loop, you then try to access that one-element vector with
w(2)
but there is no second element, so you get that error.
It looks like there might be some other fundamental errors with your code, but it is difficult to know exactly what you intend to do, so it is difficult to give advice.

この質問は閉じられています。

製品

リリース

R2016b

タグ

質問済み:

2018 年 5 月 29 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by