How to vectorize the for loop
显示 更早的评论
Dear all,
I am trying to vectorize the following statement:
u=zeros(n,2,2);
v=zeros(N);
w=zeros(n,2,2);
for j=1:n
u(j,1,1)=v(j)*w(j,1,1);
end
The vectorized version:
j=1:n
u(j,1,1)=v(j)*w(j,1,1);
But I got the error message:
Inner matrix dimensions must agree
because N>n.
Would you please suggest a way to resolve this problem? Thank you.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!