How convert for loop to while loop?
3 次查看(过去 30 天)
显示 更早的评论
I must convert that for loop to while loop. How can I do that? I tried somethings but I couldn't get right result.
A=zeros(5,8);
[r,c]=size(A);
%for loop
for i=1:r % loops over rows
for j=1:c % loops over columns
if i>j
A(i,j)=4*i-2*j;
elseif i<=j
A(i,j)=i^2-3*j;
end
end
end
A
0 个评论
采纳的回答
KSSV
2020-5-23
A=zeros(5,8);
[r,c]=size(A);
%for loop
i = 0 ;
while i<r % loops over rows
i = i+1 ;
j = 0 ;
while j<c % loops over columns
j = j+1 ;
if i>j
A(i,j)=4*i-2*j;
elseif i<=j
A(i,j)=i^2-3*j;
end
end
end
A
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!