How to find index of a value in cell array
114 次查看(过去 30 天)
显示 更早的评论
I have this Cell Array ‘A’ of size 3 by 7
A = { 3 4 [] [] [] [] []
2 6 -2 2 -2.1 2 2
-5 -5 25 1 [] [] []}
I want to find index of ‘6’ element in 2nd row and 2nd column The answer shall be row = 2 and column = 2
0 个评论
采纳的回答
the cyclist
2017-1-25
编辑:the cyclist
2017-1-25
isSix = cellfun(@(x)isequal(x,6),A);
[row,col] = find(isSix);
4 个评论
更多回答(1 个)
Walter Roberson
2017-1-25
Re-using the framework of my answer to your earlier question:
B = A;
B(cellfun(@isempty, B)) = {NaN};
[maxrow, maxcol] = find( reshape(cell2mat(B), [], 1) == 6);
1 个评论
Walter Roberson
2024-11-8,4:40
Looking again several years later, it looks like the code should use
[maxrow, maxcol] = find( cell2mat(B) == 6);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!