2011-06-23 86 views
4

我需要刪除其中具有相同值的矩陣中的任何列。我在MATLAB中使用for-loop來設計它。我想知道是否存在使用矢量化的更好/更快的方法。刪除在MATLAB中具有相同值的任何列

mat = [ 0.56 0.2 1 0 45; 0.566 0.2 4 0 45; 0.52 0.2 6 0 45; 0.56 0.2 6 0 41 ]; 
[row col] = size(mat) ; 

bitmat = true(1,col) ; 
for i = 2:row, tf = (mat(i-1,:) == mat(i,:)) ; bitmat = bitmat & tf ; end 
mat(:,bitmat) = [] ; 

謝謝!

回答

4

下面是一個使用功能DIFFANY一個簡單的一行:

mat = mat(:,any(diff(mat,1))); 
相關問題