2012-02-23 7 views
1

N行の列を別の列にコピーする代わりに、可能であれば移動できますか?N行のセットをMATLABの別の列に移動

これは、行を別の列にコピーするコードです。

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

別の列に移動する方法を見つける必要があります。

お知らせください。

+0

、あなたは何に手の込んだことができあなたは "移動"(望ましい動作、行列のサイズへの影響、他の列)を意味しますか? –

答えて

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

を2列のスワップ:上書きと

%# 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) = []; 
関連する問題