adding coloum
4 次查看(过去 30 天)
显示 更早的评论
how to add a column on a matrix ??
2 个评论
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.
回答(2 个)
Image Analyst
2011-11-24
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)]
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!