问题
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