Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Cam Salzberger
Cam Salzberger am 17 Mai 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by