For the sake of simplicity, let's assume you're using vectors called X
and Y
(of the same length), and you want to remove only those entries where both vectors are zero. Here's how (not tested):
% Find the indexes where either X or Y is different from zero
% (these are the indexes of the components we want to keep)
I = find(X~=0 | Y~=0);
% Select the desired components from X and Y
X=X(I);
Y=Y(I);
Edit: As Oli has pointed out below (and stefano explained further), you should use logical indexing for better performance.