필터 지우기
필터 지우기

Add first row of matrix A to matrix B

조회 수: 8 (최근 30일)
Didi Lovato
Didi Lovato 2022년 3월 8일
편집: Les Beckham 2022년 3월 8일
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
Les Beckham
Les Beckham 2022년 3월 8일
편집: Les Beckham 2022년 3월 8일
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).

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

답변 (1개)

Max Alger-Meyer
Max Alger-Meyer 2022년 3월 8일
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,:)
B = 2×3
10 20 30 18 22 46
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,:)
B = 3×3
12 14 16 18 22 46 10 20 30
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,:)
B = 3×3
10 20 30 12 14 16 18 22 46

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by