table less than operator

hi,
I'm having this error : Undefined operator '<' for input arguments of type 'table'.
how can I write the operator less than for table?
I ttied using gt(A,B) and lt(A,B) but it still give me this error.
I still want to use table and not to convert the table to array.
thanks!

2 Comments

What does it mean to you for a table to be less than something? Are you sure you do not instead want to compare the content of a variable in the table to something?
sani
sani on 17 Jan 2020
Hi,
yes this what I'm trying to do

Sign in to comment.

Answers (1)

Are you sure you do not instead want to compare the content of a variable in the table to something?... yes this what I'm trying to do.
Then why are you trying to apply < or > to the entire table? You should be applying it to a specific variable, like in the following example:
T =
5×6 table
LastName Age Smoker Height Weight BloodPressure
_________ ___ ______ ______ ______ _____________
'Sanchez' 38 true 71 176 124 93
'Johnson' 43 false 69 163 109 77
'Li' 38 true 64 131 125 83
'Diaz' 40 false 67 133 117 75
'Brown' 49 true 64 119 122 80
>> T.Age<=40
ans =
5×1 logical array
1
0
1
1
0

7 Comments

maybe this will help to understand what I'm tring to do:
this is my code, and I want to compare between the cell in the i location to the cell (i-1) location for the entire table, and if the cell (i-1) equal less than the cell value i than the cell in the location i will be equal to the sum of the values of cells i and i-1
prev = 0;
sum = 0;
for i = 2:height(T1(:,1))
if lt(prev,T1.time(i))
sum = sum + prev;
end
prev = T1(i,1);
T1.time(i) = T1.time(i)+sum;
end
prev = 0;
That is a specific numeric value.
if lt(prev,T1.time(i))
First round, you compare the specific numeric value to the numeric time. All is well.
prev = T1(i,1);
You just set prev to the entire table row - a table with an unknown number of variables and one row in it. Wouldn't it make more sense to set prev to T1.time(i) ?
sani
sani on 17 Jan 2020
yes so I guess I didn't understand table syntex well, thanks!
Correction, T1(i,1) is not an entire row, but it is a sub-table with one row and the same variable as the first variable in the table T1.
sani
sani on 17 Jan 2020
So in my case time variable in in the 1st column of the table, is it becaus this syntex call a sub-table and not for a variable it didn't worked?
Change
prev = T1(i,1);
to
prev = T1{i,1};
sani
sani on 18 Jan 2020
Thanks!

Sign in to comment.

Categories

Asked:

on 17 Jan 2020

Commented:

on 18 Jan 2020

Community Treasure Hunt

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

Start Hunting!