add collum to one matrix from another

조회 수: 2 (최근 30일)
Gustas
Gustas 2024년 9월 25일
답변: Zuber Khan 2024년 9월 25일
I want to add b33, b23, b11 to matrix a between first and second collum
A=[3 7 13;-8 -3 -4; 6 8 17]
B=[6 -4 -3; -11 14 -12;-15 12 -2]
C= A(:,1),
  댓글 수: 2
Stephen23
Stephen23 2024년 9월 25일
Please show us the expected output.
DGM
DGM 2024년 9월 25일
B(3,3), B(2,3), B(1,1) don't constitute a column from B.
C is a column from A.
We have two arrays A and B, and two vectors. What goes where?

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

답변 (1개)

Zuber Khan
Zuber Khan 2024년 9월 25일
Hi,
You can create a column vector from b33, b23 and b11 which refer to third element of the third column of matrix B, second element of the third column of matrix B and first element of the first column of matrix B respectively.
Then this column vector can be easily added between the first and second columns of A.
I am attaching a code snippet for your reference.
ColumnVec = [B(3,3);B(2,3);B(1,1)]; % assuming order is b33, b23 and b11
A_new = [A(:,1),ColumnVec, A(:,2:end)];
I hope it addresses your query.
Regards,
Zuber

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by