Comparing table values using IF statements

28 views (last 30 days)
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

Answers (1)

Jeff Miller
Jeff Miller on 26 May 2019
Change
if uRiDdD(k,1) == allContacts(i,1)
to
if uRiDdD{k,1} == allContacts{i,1}
  4 Comments
Jeff Miller
Jeff Miller on 26 May 2019
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'.

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!