Add first row of matrix A to matrix B
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can i add first row of matrix A to matrix B
a= [10 20 30 ;
40 50 6; ]
b= [ 12 14 16;
18 22 46; ]
1 Kommentar
Les Beckham
am 8 Mär. 2022
Bearbeitet: Les Beckham
am 8 Mär. 2022
Also, you should be aware that Matlab is case sensitive. So, if you want to "add first row of matrix A to matrix B", you first have to define A and B (not a and b).
Antworten (1)
Max Alger-Meyer
am 8 Mär. 2022
I'm not totally sure what you're asking specifically, so here are answers to all of the different possibilities of things I think you might mean.
A = [10 20 30; 40 50 6];
B = [12 14 16; 18 22 46];
Option 1: Replace first row of B with first row of A:
B(1,:) = A(1,:)
Option 2: Add first row of A to the end of B without replacing any of B:
B = [12 14 16; 18 22 46];
B(3,:) = A(1,:)
Option 3: Add first row of A to B without replacing any of B, and in doing show shift the rest of B down one row:
B = [12 14 16; 18 22 46];
B(2:3,:) = B;
B(1,:) = A(1,:)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!