I'm trying to figure out how to extract rows from a table if a certain variable of a row has a certain value. I know how to do this in R but can't figure it out in Matlab. For example, let's say this is my table:
Var1 Var2 Var3
_____ _____ ______
1.0 2.0 'class 1'
1.1 2.1 'class 2'
1.2 2.2 'class 3'
1.3 2.3 'class 1'
I'm trying to figure out how to get all the rows where Var3 has the value "class 1". Concretely, I want this:
Var1 Var2 Var3
_____ _____ ______
1.0 2.0 'class 1'
1.3 2.3 'class 1'
So far, I've tried using a keyword argument, outlined in this post, as well as using matlab rows to try and sort everything. Neither has worked.
Let's say T is my table. First, I tried
T(T.Var5 == 'class 1',:)
but got the error:
Undefined operator '==' for input arguments of type 'cell'.
Then, I decided to get a little creative, and saw you could create row names in the Matlab documentation. So I did this:
A = T{:,{1:2}};
B = T{:,{3}};
B = table2array(B);
A.Properties.RowNames = B;
but I got the error:
Duplicate row name: 'class 1'.
Am I doing something wrong here? Is there an easy way to do this in Matlab?
Any help is appreciated. Thanks.