v_m generates a 2 by 5 matrix. inside the for loop at the point after 'else'(basically when i==2), then i am getting an error saying : index exceeds matrix dimensions. why does it happen? when i manually write this: a=alpha0(2); i get the 2nd element of that matrix, but it does not seem to work when it is inside the loop.
alpha0=v_m(:,1);
for i=1:2
if i==1
alpha0=alpha0(i);
else
alpha0=alpha0(i);
end
end

2 个评论

I've formatted your code. Do you see, that it is easier to read with a proper indentation? Use Ctrl-A Ctrl-I in Matlab's editor.

请先登录,再进行评论。

 采纳的回答

Jan
Jan 2018-2-22
编辑:Jan 2018-2-22
In the first iteration, i=1, you evaluate
alpha0 = alpha0(i);
This replaces the vector alpha0 by the scalar alpha0(1). Afterwards, alph0(2) does not exist anymore.
I cannot imagine the purpose of the shown code. Therefore it is hard to suggest a solution. Maybe
alpha0 = v_m(:,1);
for i=1:2
currentAlpha0 = alpha0(i);
... and here the computations
end

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by