Comparing table values using IF statements

45 visualizaciones (últimos 30 días)
Isabelle van Vuuren
Isabelle van Vuuren el 25 de Mayo de 2019
Comentada: Jeff Miller el 26 de Mayo de 2019
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

Respuestas (1)

Jeff Miller
Jeff Miller el 26 de Mayo de 2019
Change
if uRiDdD(k,1) == allContacts(i,1)
to
if uRiDdD{k,1} == allContacts{i,1}
  4 comentarios
Isabelle van Vuuren
Isabelle van Vuuren el 26 de Mayo de 2019
Sure, here is a sample of the data in the table
Jeff Miller
Jeff Miller el 26 de Mayo de 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'.

Iniciar sesión para comentar.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by