"Garrett Pataky" <pataky.removethis.2@illinois.edu> wrote in message
news:ic16k5$rm1$1@fred.mathworks.com...
> I have a matrix X and a matrix Y both with 100 points. Matrix X has
> negative values that I want to remove. Lets say I have 20 negative
> points, so I can remove them, but now I am left with X having 80 points
> and Y having 100 points. I need these two matricies to be the same size.
>
> How can I remove the points corresponding to the points I removed from X
> from the Y matrix as well? Thanks.
Logical indexing with either a vector of points to remove or a vector of
points to keep.
% Sample data
X = randn(1, 100);
Y = rand(1, 100);
% Operate on a copy so you can compare
X2 = X;
Y2 = Y;
% Remove points
pointsToRemove = X < 0;
X2(pointsToRemove) = [];
Y2(pointsToRemove) = [];
% Keep points, operating on a copy
X2 = X;
Y2 = Y;
pointsToKeep = X >= 0;
X2 = X2(pointsToKeep);
Y2 = Y2(pointsToKeep);
These are not _exactly_ the same if X or Y contain NaN values, but you will
need to decide how to handle that situation if or when it arises.

Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
