Find similar values from different tables

11 ビュー (過去 30 日間)
stelios loizidis
stelios loizidis 2021 年 9 月 29 日
コメント済み: stelios loizidis 2021 年 10 月 8 日
Hello.
I have two matrices, the A1 (270X1) and the A2 (171X1). Matrix A2 has some values, which are the same as some of matrix A1. What I want is to find in which positions matrix A1 has the same values as matrix A2. Below I have the code I wrote but the issue is that in k1 there is the position of the last same value that the two matrices have. There are no other positions for all other same values.
% A1:270X1, A2:171X1
for i=1:length(A2)
[k1,z1]=find(A1==A2(i));
end
Your help is invaluable !!

採用された回答

Srivardhan Gadila
Srivardhan Gadila 2021 年 10 月 8 日
You can make use of unique function and also the syntax "k = find(X)" for find function should be sufficient as A1 and A2 are just vectors and not matrices.
The following code might help you (update the code if required according to your use case):
% Get the unique elements from A2
U = unique(A2);
% Iterate through unique elements of A2 to find if and where they are
% located in A1
for i = 1:length(U)
k{i} = find(A1==U(i));
end
  1 件のコメント
stelios loizidis
stelios loizidis 2021 年 10 月 8 日
It works!! Thanks for the valuable, help !!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by