Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
MATLAB で行列の最も繰り返される (モーダル) 行を見つける関数を探しています。何かのようなもの:
>> A = [0, 1; 2, 3; 0, 1; 3, 4] A = 0 1 2 3 0 1 3 4
次に実行します:
>> mode(A, 'rows')
を返し[0, 1]、理想的には、この行が発生したインデックスを示す 2 番目の出力 (つまり[1, 3]'.)を返します。
[0, 1]
[1, 3]'
誰かそのような機能を知っていますか?
UNIQUEを使用して一意の行インデックスを取得し、それらに対してMODEを呼び出すことができます。
[uA,~,uIdx] = unique(A,'rows'); modeIdx = mode(uIdx); modeRow = uA(modeIdx,:) %# the first output argument whereIdx = find(uIdx==modeIdx) %# the second output argument
答えは正しくないかもしれません。A = [2, 3; を試してください。0、1; 3、4; 0、1]。次のようにする必要があります。
[a, b, uIdx] = unique(A,'rows'); modeIdx = mode(uIdx); modeRow = a(modeIdx,:) %# the first output argument whereIdx = find(ismember(A, modeRow, 'rows')) %# the second output argument