Eliminate zeros from array

2 visualizaciones (últimos 30 días)
Inês Correia
Inês Correia el 30 de Abr. de 2018
Respondida: James Tursa el 30 de Abr. de 2018
I have to arrays: A=[0 1 0 4; 2 0 3 4] and B= [1 2 3 4; 5 6 7 8]
I want to eleiminate zeros from matrix A and the corresponding values from matrix B. The solution is:
A=[1 4 2 3 4] and B=[2 4 5 7 8]

Respuestas (1)

James Tursa
James Tursa el 30 de Abr. de 2018
AT = reshape(A',1,[]);
BT = reshape(B',1,[]);
B = BT(AT~=0);
A = AT(AT~=0);

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by