フィルターのクリア

suppose i have two dataset p and q and need to compare?? but how if its in excel file ??

3 ビュー (過去 30 日間)
wasima tammi
wasima tammi 2015 年 5 月 24 日
コメント済み: Image Analyst 2015 年 5 月 25 日
i have 2 dataset p and q and i want to compare 1st row all columns of p with each row with all columns of q and want to count that number which it matches??
but how?
i have written the following code buy it doesnt show the resuts properly....
count=0;
for i=1:size(p,1)
for j=1:size(q,1)
if all(p(i,:)==q(j,:))
count=count + 1;
end
end
end
can anyone plz help as its urgent..:D..thanks in advance

回答 (2 件)

Image Analyst
Image Analyst 2015 年 5 月 24 日
To compare floating point numbers, you need to use a tolerance. See the FAQ for code examples:
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 24 日
Instead of having all(p(i,:)==q(j,:)) instead have tolerance = 0.000001;
if all( abs(p(i,:)-q(j,:)) < tolerance )
here you should adjust tolerance for your situation.
Image Analyst
Image Analyst 2015 年 5 月 25 日
If p and q are integers, then there's no problem. The problem is only for floating point numbers.

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


Walter Roberson
Walter Roberson 2015 年 5 月 24 日
In the case where you do not need to worry about floating point round-off (such as if you are using integral values), then
counts = zeros(size(p),1));
for K = 1:size(p,1)
counts(K) = sum( ismember(q, p(K,:), 'rows') );
end
This would give a per-row count. You can then sum(counts) to get the total number of matches. (Note that identical rows in p would get counted multiple times in that sum.)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by