How do I replace multiples of 4 with a 0 in a magic 4 matrix?

2 次查看(过去 30 天)
I have googled and tried and done everything I can think of and still can't get this to work. Can someone please help me?
  1 个评论
Noah Franks
Noah Franks 2019-10-22
%Solution to P6
disp ('P-6');
res=0;
A=magic(4);
for row=1:4
for col=1:4
if A(mod(A,4)==0)==0
res=mat;
end
end
end
disp(res);
This is my code.

请先登录,再进行评论。

回答(3 个)

David Hill
David Hill 2019-10-22
a=magic(4);
a(mod(a,4)==0)=0;

Noah Franks
Noah Franks 2019-10-22
To the two gentleman who answered my question, it didn't work.

Cre'Shawn Dabney
Cre'Shawn Dabney 2019-10-23
Hey Noah this should be the code. Just incase you didnt get it yet.
disp('P-6');
res=0;
a=0;
for row=1:4
for col=1:4
if mat==mat
a=magic(4);
a(mod(a,4)==0)=0;
end
end
end
disp(a);

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by