Comparing table values using IF statements
조회 수: 28 (최근 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에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!