add a column between tow columns
显示 更早的评论
Hi,
I am newbie with matlab. I have a matrix like:
a = [ 2 5 7 ; 3 6 8]
I would like to add new column between column 1 and 2, So I will have:
a = [2 1 5 7; 3 4 6 8]
Let me ask it more general, I want to add a column between any two columns.
Thanks
采纳的回答
更多回答(3 个)
Adam
2014-5-29
1 个投票
Hi, look here http://www.mathworks.com/matlabcentral/answers/1085-inserting-a-column-in-a-matrix-without-deleting-any-column
If you use it often, some function handling it should not be problem to program.
Adam
Jos (10584)
2014-5-29
% DATA
A = [1 2 3 ; 4 5 6] % original matrix
x = [8 ; 9] % values to insert
J = 2 % insert x AFTER column J into A
% ENGINE
B = [A x]
[~,i] = sort([1:size(A,2) J])
B = B(:,i)
类别
在 帮助中心 和 File Exchange 中查找有关 Crystals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!