Info

This question is closed. Reopen it to edit or answer.

Eliminate values from a column vector if two conditions are true

1 view (last 30 days)
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

Answers (1)

Image Analyst
Image Analyst on 30 Sep 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!