フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to compare two different matrix and set a counter to calculate how many rows matches with all its columns??

1 回表示 (過去 30 日間)
wasima tammi
wasima tammi 2015 年 3 月 20 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
% count1=0;
%for i=1:size(p1)
% for j=1:size(q1)
% if find ( p1(i,:)==q1(j,:))
% count1=count1 + 1;
%
%
% end
% end
% end
the counter is giving wrong count and how to adjust it..and when i m using here a variable instead of counter then the command prompt returns that it was an undefined function or variable...

回答 (3 件)

Image Analyst
Image Analyst 2015 年 3 月 20 日
Why not simply do
% Get number of rows and columns.
[rows, columns] = size(p1);
% Find number of columns where each element matches.
numMatchingElements = sum(sum(p1==q1) == rows)
?
It's vectorized and uses only 1 line of code (or 2 if you don't know the number of rows in advance).

Roger Stafford
Roger Stafford 2015 年 3 月 20 日
You are misusing the 'if' function. Where you write
if find ( p1(i,:)==q1(j,:))
the condition will be considered true if any of the elements match, not just if they all match. You should write this for a complete match:
if all(p1(i,:)==q1(j,:))
  1 件のコメント
wasima tammi
wasima tammi 2015 年 3 月 20 日
thanks for ur answer.. but the thing is that when i run the program it shows that the count is undefined variable or function which is actually not.. for this what i can do??

James Tursa
James Tursa 2015 年 3 月 20 日
The above code is all commented out (begins with % and appears green in the editor). Is this the actual code you are trying to run? (It won't run because it is commented out)
  1 件のコメント
wasima tammi
wasima tammi 2015 年 3 月 20 日
ya its commented out as i have written here .. and this is one part of the code for that reason i commented those parts for debugging ..!

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by