2つ以上の同じ要素を持つ列を削除
显示 更早的评论
2つ以上の同じ要素を持つ列を削除したいです。
unique関数を使うのでしょうか?
良い手法を教えていただけますと助かります。
before
1 2 3 4 5
2 3 4 4 6 -削除
7 5 5 5 2 -削除
0 9 7 8 1
after
1 2 3 4 5
0 9 7 8 1
采纳的回答
更多回答(1 个)
arrayfun 使った別の方法:
% 配列の一例 (行・列数は任意)
A = [...
1 2 3 4 5;...
2 3 4 4 6;... % -> 削除
7 5 5 5 2;... % -> 削除
0 9 7 8 1];
% 各行のユニークな要素数
nElement = arrayfun(@(x) numel(unique(A(x,:))), 1:size(A,1));
% ユニークな要素数がAの列数と同じ行インデックスを作成
idx = nElement == size(A,2);
% 対象の行のみ残す
A = A(idx,:);
% 結果を表示
disp(A)
类别
在 帮助中心 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!