MATLAB: How to recover removed negatives and null values and place them in the same vector

findzeros

Let Y a column vector that i eliminate zeros and negatives values using :
Y(Y<=0)=[];
How can i get the initial vector Y using indices of removed values?
Thanks in advance

Best Answer

Once they're gone, they're gone. Knowing where they were won't help you because they're gone. If you need them later, you need to save either the original y
yOriginal = y; % Save before deleting elements.
or save the deleted values before deleting them
indexesToDelete = Y < 0;
elementsToDelete = Y(indexesToDelete); % Extract and save elements before deleting them.
Y(indexesToDelete) = []; % Delete them permanently.