adding coloum

how to add a column on a matrix ??

댓글 수: 2

Jan
Jan 2011년 11월 24일
This question is exhaustively answers by the Getting Started chapters of the documentation. It is strongly recommended to read these chapters, if you want to use such a powerful language as Matlab.
Andrei Bobrov
Andrei Bobrov 2011년 11월 24일
I totally agree with Jan!

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

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2011년 11월 24일

0 개 추천

A = [1 2 3;4 5 6]
B = [7;8]
C = [A,B]
or
C = A;
C(:,end+1) = B
Image Analyst
Image Analyst 2011년 11월 24일

0 개 추천

Try this little demo. It should be rather self explanatory and fairly robust:
% Generate some sample data
rows = 4;
M = magic(rows)
columnToInsert = ones(rows,1)
% Append the column.
appendedM = [M columnToInsert]
% Prepend the column.
prependedM = [columnToInsert M]
% Insert the column in the middle somewhere.
newColNumber = 3;
insertedM = [M(:, 1:newColNumber-1), columnToInsert, M(:, newColNumber:end)]

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2011년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by