Borrar filtros
Borrar filtros

finding the index of an array in cell array

2 visualizaciones (últimos 30 días)
Izzat Brgli
Izzat Brgli el 28 de Mzo. de 2021
Comentada: Stephen23 el 30 de Mzo. de 2021
I'm trying to find out if an array is an element of a cell array and return the index, so I did
arr ={[1,2,3],[4,45,6]}
index = find([arr{:}] == [1,2,3])
but it didn't work. How can I solve it?
thanks in advance

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 29 de Mzo. de 2021
Editada: Fangjun Jiang el 29 de Mzo. de 2021
arr ={[1,2,3],[4,45,6]};
>> index=find(cellfun(@(x) all(x==[1 2 3]),arr))
index =
1
  1 comentario
Stephen23
Stephen23 el 30 de Mzo. de 2021
Simpler and more efficient to use isequal:
arr = {[1,2,3],[4,45,6]};
vec = [1,2,3];
fun = @(a)isequal(vec,a);
idx = cellfun(fun,arr)
idx = 1×2 logical array
1 0

Iniciar sesión para comentar.

Más respuestas (0)

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