Using find for table values
Show older comments
I have a table that is 1764x1, lets call it T. Each value is either 100, 90, 80 or 73. I want to find the indicies of these values in my table. I have tried using find(T==100) to find these values but then i get the error:
"Operator '==' is not supported for operands of type 'table'."
So I try to convert it using table2array(T) but then T turns into a categorical type and when i try to use find with the convertet T i get the error saying "Invalid types for comparison."
How can I find the indicies of specific values in my table?
1 Comment
Rik
on 8 Dec 2021
I suspect ismember will help. Can you give a small example of your data?
Note that a table contains variables, not values. That means you have to select the correct variable first.
Accepted Answer
More Answers (1)
dpb
on 8 Dec 2021
Rik's second comment is the pertinent one here -- you're appying the function to the entire table, not a variable within the table.
ix=find(T.Var1==100);
will address the variable named 'Var1' -- use the correct name for the variable of interest from your own table, of course, in place.
NB: the other comment as well plus another of my own -- it is often not needed to actually use find and convert the logical expression into actual row numbers --
T.Var1(T.Var1==100)
returns the same elements directly from the logical addressing vector.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!