Borrar filtros
Borrar filtros

How to find index of a value in cell array

68 visualizaciones (últimos 30 días)
Vishal Sharma
Vishal Sharma el 25 de En. de 2017
Comentada: Kristoffer Walker el 13 de Dic. de 2019
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

Respuesta aceptada

the cyclist
the cyclist el 25 de En. de 2017
Editada: the cyclist el 25 de En. de 2017
isSix = cellfun(@(x)isequal(x,6),A);
[row,col] = find(isSix);
  3 comentarios
hyunglok kim
hyunglok kim el 26 de Mzo. de 2018
This answer is the best.
Kristoffer Walker
Kristoffer Walker el 13 de Dic. de 2019
Not at all intuitive, but it works great, even for logicals.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 25 de En. de 2017
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);

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by