Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Eliminate values from a column vector if two conditions are true

1 visualización (últimos 30 días)
MARIA SOFIA AMALFITANO
MARIA SOFIA AMALFITANO el 30 de Sept. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi. I need to eliminate zero values from column vectors S1 and F1, just when I have the zero in both cases. I tried these two codes but both give different errors. How should I do it??
J1 is the number of observations that I have.
for k=1:1:J1
if (S1vero(k,1) == 0 && F1vero(k,1) == 0);
S1vero (k,1) = []
F1vero (k,1)= []
end
end
for k=1:1:J1
if (S1garbled(k,1) == 0 && F1garbled(k,1) == 0);
S1garbled (k,1) = []
F1garbled (k,1) = []
end
end
for k=1:1:J1
if (S1vero(k,1) == 0 && F1vero(k,1) == 0);
S1vero (k,1) = nonzeros(S1vero(k,1)');
F1vero (k,1)= nonzeros(F1vero(k,1)');
end
end

Respuestas (1)

Image Analyst
Image Analyst el 30 de Sept. de 2019
Try this:
elementsToDelete = F1 == 0 & S1 == 0;
F1(elementsToDelete) = [];
S1(elementsToDelete) = [];

Community Treasure Hunt

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

Start Hunting!

Translated by