Azzera filtri
Azzera filtri

How to obtain the indexes of numbers in a cell array with mixed data?

4 visualizzazioni (ultimi 30 giorni)
I have different cell arrays like:
cellArray1={'PGD',[23095],[5226],[NaN],[NaN]};
cellArray2={[12342],[NaN],[NaN],[NaN],[NaN]}
cellArray3={'A1','APIT','CRT',[378708],[100526739]}
and I would like to obtain the indexes of the numbers in the array such as:
indexes1= 2,3
indexes2= 1
indexes3= 4,5
respectively
Cheers

Risposta accettata

Cam Salzberger
Cam Salzberger il 17 Mag 2017
You can use "cellfun" to run the is* style functions for every cell in a cell array. For your particular use-case, you seem to want only cells that are numeric and non-NaN. You could do two calls to cellfun, or just make an anonymous function that checks both:
cellfun(@(c) isnumeric(c) && ~isnan(c),cellArray1)
This will give you a logical array the same size as the cell array. You can choose to use "find" if absolutely necessary to get the indices out, but that usually isn't required.
-Cam

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by