comparing the two arrays

1 回表示 (過去 30 日間)
PRAVEEN GUPTA
PRAVEEN GUPTA 2019 年 8 月 12 日
回答済み: Stephan 2019 年 8 月 12 日
i am trying to compare the two different array in loop to get the number of times the value are coming in X1 which are in X2 but i m getting the wromg answer
clc
clear all
x1=[1,2,3,2,0,3,4,3,5,4,5,6,8];
x2=[3,0];
for m=1:length(x2)
for i=1:length(x1)
s(m)=(nnz((x1(i))==x2(m)));
end
end
s

採用された回答

Stephan
Stephan 2019 年 8 月 12 日
x1=[1,2,3,2,0,3,4,3,5,4,5,6,8];
x2=[3,0];
res = zeros(1,numel(x2));
for k = 1:numel(x2)
res(k) = sum(ismember(x1,x2(k)));
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by