필터 지우기
필터 지우기

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;
  댓글 수: 1
Tia
Tia 2013년 4월 21일
it works.. thank you

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

추가 답변 (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