2012-02-23 80 views
1

是否可以將一列N行從一列複製到另一列,我可以移動它嗎?在MATLAB中將一組N行移動到另一列

這是我的代碼'行'複製到另一列。

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

我需要找到一種方法將它們移動到另一列。

請指教。

+0

如果我的回答並沒有解決你的情況,你能否詳細說明什麼你的意思是「移動」(期望的行爲,對矩陣大小的影響,其他列)? – 2012-02-23 00:22:40

回答

1

移動列:

%# 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) ]; 

交換兩列:

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

移動與覆蓋:

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