How to add a column between two columns?

조회 수: 12 (최근 30일)
Jose Grimaldo
Jose Grimaldo 2020년 2월 5일
댓글: C'lette 2024년 2월 4일
I have a matrix 3x3 and a column vector 3x1. I'm trying to add the column vector between the second and third column of the 3x3 matrix.How can i add the column to the matrix?
M1=randi([-10,20],[3,3]); % M1 is 3x3 matrix
r=[5;5;5]; % r is 3x1 vector

채택된 답변

Adam Danz
Adam Danz 2020년 2월 5일
편집: Adam Danz 2020년 2월 5일
out = [M1(:,1:2), r, M1(:,3)];
  댓글 수: 1
C'lette
C'lette 2024년 2월 4일
I suggest a little change, just to avoid hardcoding:
out = [M1(:,1:2), r, M1(:,3:end)];

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by