How to compare two matrix and then count each elements?
3 ビュー (過去 30 日間)
古いコメントを表示
The elements of A will be checked and compared with B, with each element count S will increase and with each absence count R will increase.
A=[3 5 7]
B=[1 3 4 5 7]
5 件のコメント
Stephen23
2018 年 6 月 8 日
"I want to count how many similar elements are there in A in compare to B"
That is what my answer does. You might also like to read about intersect and setdiff.
採用された回答
Stephen23
2018 年 6 月 6 日
Some variety of these might do what you want (although those examples are not very enlightening)
>> S = nnz(ismember(A,B))
S = 3
>> R = nnz(ismember(B,A))
R = 3
その他の回答 (1 件)
Pratik Panchal
2018 年 6 月 6 日
It is not clear whether S and R are increasing if the values of A are same as values of B or regardless. Also what do you mean by 'absence'?
Anyway for the comparison You can use a for loop in this.
for k=1:length(A)
for j=1:length(B)
if A(k)==B(j);
%Insert your condition here
else
%Insert your second condition here
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!