Operands to the || and && operators must be convertible to logical scalar values.
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
So I don't understand the reason why I am getting the following error:
riskUserId=[];
if (data.A>5) || (data.B==1)
C=data.D;
end
data is a table
A is of type double
B is of type logical (0s and 1s)
I am still getting used to this table logic and cell content type of data.
2 Kommentare
Geoff Hayes
am 5 Mai 2022
data.Age>60
? Should there be one age greater than 60 or all ages greater than 60?
Antworten (2)
Mitch Lautigar
am 5 Mai 2022
riskUserId=[];
%MATLAB is expecting a 1 or 0 for preexisting conditions. IF the values in the table are true/false, use strcmpi(). This would look like (strcmpi(data.Preexisting_Conditions,"true"))
if (data.Age>60) || (data.Preexisting_Conditions==1)
riskUserId= [riskUserId;data.User_ID]; %Stack all values into an array for easy viewing.
end
Cris LaPierre
am 5 Mai 2022
Bearbeitet: Cris LaPierre
am 5 Mai 2022
Use || and && when you are comparing a single (scalar) value. Use | and & when you are comparing arrays (when there is more than 1 output of the comparison).
a = 1:4;
b = 4:-1:1;
% Works
c = a>2 & b<=3
% Error you are seeing
d = a>2 && b<=3
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!