How to obtain the indexes of numbers in a cell array with mixed data?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Cam Salzberger
2017-5-17
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!