How to Vectorize if statement
显示 更早的评论
Dear all,
Here is part of my code for vectorizing the for loop and if statement:
u=zeros(N,1);
du=zeros(n,1);
j=1:1:n
du(rem(j,5)==1)=u(j+1)-u(N+(j-rem(j,5));
du(rem(j,5)~=1)=u(j+1)-u(N+(j-rem(j,5)-1);
but i got the following error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Can anyone point out the error for me? 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!