can you fix this matrix?

2 次查看(过去 30 天)
Tia
Tia 2013-4-20
m=ones(4);
x=-1;
for i=1:3;
m(1,1)=-x;
m(1,1+i)=x;
m(2:end,1:end)=x;
end
i want to make it's shorter and easier. can you fix it?
example:
[1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1]
i want the output will be
[1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1]
thank you very much
  1 个评论
Walter Roberson
Walter Roberson 2013-4-20
Why are you re-assigning m(1,1) during each iteration of the "for" loop?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2013-4-20
m = -ones(4);
m(1,1) = 1;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by