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

35 vues (au cours des 30 derniers jours)
Centauri Jolene
Centauri Jolene le 16 Avr 2019
Commenté : Centauri Jolene le 16 Avr 2019
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'

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur MATLAB Compiler dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by