Comparing table values using IF statements

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
askForHelp2.PNG
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

Réponses (1)

Jeff Miller
Jeff Miller le 26 Mai 2019
Change
if uRiDdD(k,1) == allContacts(i,1)
to
if uRiDdD{k,1} == allContacts{i,1}

4 commentaires

Hi Jeff, thanks for your help
Unfortunately still getting an error:
Undefined operator '==' for input arguments of type 'cell'.
Error in processing (line 38)
if uRiDdD{k,1} == allContacts{i,1}
Jeff Miller
Jeff Miller le 26 Mai 2019
Could you attach examples of these two to-be-compared tables to your post as mat files (at least the first 10-20 rows)? It isn't entirely clear from your original post how matlab is storing these tables (i.e., what data type is in each cell).
Sure, here is a sample of the data in the table
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'.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Printing and Saving dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by