Find row index of first 'True' value in column of table

36 views (last 30 days)
I have a table (called T) of multiple columns of different types (int & string). One column (called 'active' - last column) is made up of 'True' and 'False' values.
I need to get the row index corresponding to the first instance of a 'True' value in that specific column.
When i subset this column out, using x = T.active; I get a cell containing the True/False strings.
The data looks like this:
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995400000000 0.320874800000000 -0.243447200000000 -0.391341200000000 3 0.600000000000000 0.300000000000000 'False' 'False'
0.533995200000000 0.320874700000000 -0.243447100000000 -0.391341100000000 3 0.600000000000000 0.300000000000000 'False' 'True'
0.533995300000000 0.320876000000000 -0.243452500000000 -0.391338100000000 3 0.600000000000000 0.300000000000000 'False' 'True'
0.533996300000000 0.320879000000000 -0.243463900000000 -0.391332500000000 3 0.600000000000000 0.300000000000000 'False' 'True'
0.533998800000000 0.320884400000000 -0.243480800000000 -0.391323600000000 3 0.600000000000000 0.300000000000000 'False' 'True'

Accepted Answer

Walter Roberson
Walter Roberson on 16 Apr 2019
[~, idx] = ismember('True', T.active);
It will be 0 if none match.
  1 Comment
Centauri Jolene
Centauri Jolene on 16 Apr 2019
Thank you. This also worked for me:
idx = find(strcmp(T.active, 'True'), 1);

Sign in to comment.

More Answers (1)

KSSV
KSSV on 16 Apr 2019
Let T be your table.
idx = contains(T.active,'True') ;
iwant = find(idx)
T(idx,:)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!