Borrar filtros
Borrar filtros

delate a specific number in an array and the number that have the index corresponding to the this number in an other array

1 visualización (últimos 30 días)
If I have two array A and B:
A=[0,0,3,4,5,6,7,8,9,0]
B=[10,9,8,7,6,5,4,3,2,1]
I want to delate the 0 in A and the number that have the index corresponding to the 0 in B obtaining:
A=[3,4,5,6,7,8,9]
B=[8,7,6,5,4,3,2]
To do that I would do a cycle with an if. I imagine is a common problem. Is there a simpler way to do it?
Thanks

Respuesta aceptada

Jan
Jan el 22 de Feb. de 2022
Editada: Jan el 22 de Feb. de 2022
A=[0,0,3,4,5,6,7,8,9,0];
B=[10,9,8,7,6,5,4,3,2,1];
match = (A == 0);
A(match) = []
B(match) = []
Or the other way around:
match = (A ~= 0);
A = A(match)
B = B(match)

Más respuestas (1)

David Hill
David Hill el 22 de Feb. de 2022
A=[0,0,3,4,5,6,7,8,9,0];
B=[10,9,8,7,6,5,4,3,2,1];
idx=A==0;
A(idx)=[];
B(idx)=[];

Categorías

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

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by