필터 지우기
필터 지우기

assigning values to a matrix

조회 수: 155 (최근 30일)
William Hou
William Hou 2021년 1월 6일
댓글: Walter Roberson 2021년 1월 6일
so I have this matrix,and I want everything on the 4th row to become 4s.
a=zeros(10,10)
I tried a(30,40)=4, but that altered the column instead of the rows, and also changed that highlighted position to 4, which I don't want. changing the range doesn't seen to do much to solve that. How can I assign values to the rows instead of the columns?
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 1월 6일
I think you did a(30:40)=4 to get that result.

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

답변 (1개)

Star Strider
Star Strider 2021년 1월 6일
This:
a(4,:) = 4
produces:
a =
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
4 4 4 4 4 4 4 4 4 4
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
.
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 1월 6일
a=zeros(10,10)
a = 10×10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
a(4:10:end) = 4
a = 10×10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by