Clear Filters
Clear Filters

assigning values to a matrix

155 views (last 30 days)
William Hou
William Hou on 6 Jan 2021
Commented: Walter Roberson on 6 Jan 2021
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 Comment
Walter Roberson
Walter Roberson on 6 Jan 2021
I think you did a(30:40)=4 to get that result.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 6 Jan 2021
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 Comment
Walter Roberson
Walter Roberson on 6 Jan 2021
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

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!