複数の比較対象に関してどのインデックスが一致しているかを知る方法
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yuki Koyama
le 10 Mai 2020
Commenté : Yuki Koyama
le 10 Mai 2020
たとえば,配列
11:20
に対して,
[11 12 14 14]
のように比較対象を用意します.
11は11:20の1番目の値に対応しています.同様に12は2番目,14は4番目の値です.
したがって,11:20と[11 12 14 14]を比較したとき,一致するインデックスの番号は
[1 2 4 4]
となります.
この結果を得るために,
rem((find((11:20==[11;12;14;14]).')),10)
とすることで所望の結果を得ることができましたが,もっと簡単な方法はないでしょうか?
0 commentaires
Réponse acceptée
Akira Agata
le 10 Mai 2020
ismember 関数を使うと、簡単に見つけることができます。たとえばご質問の例ですと、以下のようになります。
A = 11:20;
B = [11 12 14 14];
[~,loc] = ismember(B,A);
>> loc
loc =
1 2 4 4
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!