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

35 次查看(过去 30 天)
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'

采纳的回答

Walter Roberson
Walter Roberson 2019-4-16
[~, idx] = ismember('True', T.active);
It will be 0 if none match.

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by