Comparing table values using IF statements
6 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to check if data in one table lies between two variables in another table
The first (allDates) table is just a list of IDs in the first column and dates in the second column
the second (initialFinalDate) table looks like this

Currently I'm looing through both tables and using if statements:
% Loop through the allDates table
for i = 1:rOuter
for j = 1:cOuter
% Loop through the initialFinalDate table
for k = 1:rInner
for l = 1:cInner
% Check if the ID in allDates matches the ID in the
% initialFinalDate table
if uRiDdD(k,1) == allContacts(i,1)
% If so, add 1 to total count
result(k,4) = result(k,4) + 1;
% Check if the date is within the first week
if allContacts(i, 2) <= uRiDdD(k, 4) && allContacts(i, 2) >= uRiDdD(k, 2)
% If so, count it in the first week
result(k,2) = result(k,2)+ 1;
% Check if the date is within the last week
elseif allContacts(i, 2) <= uRiDdD(k, 3) && allContacts(i, 5) >= uRiDdD(k, 2)
% If so, count it in the last week
result(k,3) = result(k,3)+ 1;
end
end
end
end
end
end
Right now I'm getting the error:
Undefined operator '==' for input arguments of type 'table'.
Error in processing (line 38)
if uRiDdD(k,1) == allContacts(i,1)
How should I go about comparing the two tables? Thank you
0 件のコメント
回答 (1 件)
Jeff Miller
2019 年 5 月 26 日
Change
if uRiDdD(k,1) == allContacts(i,1)
to
if uRiDdD{k,1} == allContacts{i,1}
4 件のコメント
Jeff Miller
2019 年 5 月 26 日
I'm not sure what to say because I can't reproduce the error with the mat files you attached. When I load those files and then run:
k=2;
i=1;
if uRiDdD{k,1} == allContacts{i,1}
disp('equal');
else
disp('unequal');
end
there is no error. MATLAB simply prints 'unequal'.
参考
カテゴリ
Help Center および File Exchange で Printing and Saving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!