help changing the counter when converting a for loop to while loop

M=input('Enter your proposed magic square in a sigle input statement (4x4 matrix) []: ');
[r,c]=size(M);
for i=1:1:r
for j=1:1:c
a=sum(M(i,:));
b=sum(M(:,i)); % I need help converting this for
x(i)=(M(i,i)); loop into a while loop
d(i)=(M(i,5-i));
f=sum(x); % I'm not sure what to set my
g=sum(d); variables as
end
end

댓글 수: 1

You never use "j" in your "for j" loop, and you overwrite "f" and "g" during each iteration of the "for j" loop. Please repair your code first.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 3월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by