How to rename a new matrix obtained by adding a row to the previous matrix

3 views (last 30 days)
A = [1:5; 6:10]
I want to add a new row A(3,:)=11
How to name this new matrix by a new variable name. At present the new matrix' name is A again. I want it as B.
How to rename a new matrix obtained by adding a row to the previous matrix

Accepted Answer

Torsten
Torsten on 4 Apr 2025
Edited: Torsten on 4 Apr 2025
A = [1:5; 6:10]
A = 2×5
1 2 3 4 5 6 7 8 9 10
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = [A;11*ones(1,size(A,2))]
B = 3×5
1 2 3 4 5 6 7 8 9 10 11 11 11 11 11
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

More Answers (1)

Walter Roberson
Walter Roberson on 4 Apr 2025
A = [1:5; 6:10]
A = 2×5
1 2 3 4 5 6 7 8 9 10
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = A;
B(3,:) = 11
B = 3×5
1 2 3 4 5 6 7 8 9 10 11 11 11 11 11
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  4 Comments
Stephen23
Stephen23 on 4 Apr 2025
"But, will it affect the original matrix A?"
No, it will not affect A.
"I want A to be unchanged."
A will be unchanged.

Sign in to comment.

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!