confronting cell with abelians (logic values)

2 visualizaciones (últimos 30 días)
gabriele fadanelli
gabriele fadanelli el 8 de Abr. de 2020
Comentada: the cyclist el 8 de Abr. de 2020
I have a question about the way to extract some data from a cell based on some "indices" (in this case I want only to get as an output the "1-associated" values, e.g.:
A={'a' 'b' 'c'; 'd' 'e' 'f';'g' 'h' 'i'}
B=eye(3);
...formula to compare the arrays....
C={'a' '0' '0'; '0' 'e' '0';'0' '0' 'i'}
or
C={'a' nan nan; nan 'e' nan;nan nan 'i'}
I really cannot see the way to easily do it. Thanks

Respuesta aceptada

the cyclist
the cyclist el 8 de Abr. de 2020
Here is one way:
C = A;
C(~B) = {'0'};

Más respuestas (1)

Ameer Hamza
Ameer Hamza el 8 de Abr. de 2020
[A{~B}] = deal('0');
  1 comentario
the cyclist
the cyclist el 8 de Abr. de 2020
A simpler version of this idea is
A(~B) = {'0'}
Caution: this solution overwrites A itself, which you may not want.

Iniciar sesión para comentar.

Categorías

Más información sobre Multidimensional Arrays 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