How to obtain the indexes of numbers in a cell array with mixed data?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
German Preciat Gonzalez
il 17 Mag 2017
Risposto: Cam Salzberger
il 17 Mag 2017
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
0 Commenti
Risposta accettata
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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Cell 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!