Move a set of N-rows to another column in MATLAB

ⅰ亾dé卋堺 提交于 2019-12-23 03:27:10

问题


Is it possible to instead of copying a set of N-rows from a column to another column, can i possibly move it.

This is my code to 'copy' the rows over to another column.

numberofPdbs(1:235,2) = numberofPdbs(236:end,1);

I need to find a way to move them to another column.

Please advise.


回答1:


Moving a column:

%# Columns before destination are shifted back.
%# Matrix size unchanged.
data = rand(100);
desiredCol = 5;
destinationCol = 15;
data = [ data(:,1:desiredCol-1) ...
         data(:,desiredCol+1:destinationCol) ...
         data(:,desiredCol) ...
         data(:,destinationCol+1:end) ];

Swapping two columns:

%# Matrix size unchanged.
temp = data(:,destinationCol);
data(:,destinationCol) = data(:,desiredCol);
data(:,desiredCol) = temp;

Move with overwrite:

%# Destination is not preserved.
%# Matrix size decreases by 1.
data(:,destinationCol) = data(:,desiredCol);
data(:,desiredCol) = [];


来源:https://stackoverflow.com/questions/9405266/move-a-set-of-n-rows-to-another-column-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!