how to use for loop?
显示 更早的评论
Hi every one briefly, I have i=3:5 and j=1:3 and My equation is how to let i=3 for calculating the first raw and let j changes from 1:3 and for second raw i =4 and let j changes from 1:3 and third raw i =4 and let j changes from 1:3 and third
% Calculate the first row.
i=3
for j=1:3
A(i,j)=(A(i-1,1)*A(i-2,j+1)-A(i-1,j+1)*A(i-2,1))/(A(i-1,1))
end
% Calculate the second row
i=4
for j=1:3
A(i,j)=(A(i-1,1)*A(i-2,j+1)-A(i-1,j+1)*A(i-2,1))/(A(i-1,1))
end
% Calculate the third row
i=5
for j=1:3
A(i,j)=(A(i-1,1)*A(i-2,j+1)-A(i-1,j+1)*A(i-2,1))/(A(i-1,1))
end
采纳的回答
更多回答(1 个)
ES
2014-7-5
for i=3:5
for j=1:3
%calculations here.
end
end
Two suggestions: 1. Dont use i and j as variables in matlab as they denote sqrt(-1) 2. Pre allocate arrays before calculation for speed
类别
在 帮助中心 和 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!