MATLAB: Delete data with some requirements

datadeleterow

I have a coding like this:
Zx= zeros(size(X));
Zy=zeros(size(Y));
for i=1:length(X);
if Zx(i)<2.5 && Zx(i)>-2.5 && Zy(i)<2.5 && Zy(i)>-2.5
Zx(i) = (X(i) – Mean_X)/Std_X;
Zy(i) = (Y(i) – Mean_Y)/Std_Y;
else
Zx(i) && Zy(i) == 0
end
end
rowsToDelete = (Zx < -2.5 | Zx > 2.5) & (Zy <= -2.5 & Zy >= 2.5);
Xscore(rowsToDelete) = []; % Set to null.
Yscore(rowsToDelete) = []; % Set to null.
OutZscore=[X Y Zx Zy];
I also attach my data, two first coloumn is X and Y and two second column is Zx and Zy. X and Zx is a partner and Y and Zy is partner to in the same row.
I want to delete my X dan Y data with the requirement is X data wil be deleted is the requirement will explain such as (Zx<-2.5 and Zx>2.5) and (Zy<-2.5 and Zy>2.5).
The result is not satified.
I want to plot the data to compare the process before and after deleted.
Is there any one can help me I would be appreciate.
Thx

Best Answer

Try this:
D = load('Xsample_data.txt');
X = D(:,1);
Y = D(:,2);
Zx = D(:,3);
Zy = D(:,4);
Lvx = (Zx < -2.5) & (Zx > 2.5);
Lvy = (Zy < -2.5) & (Zy > 2.5);
RowsToDelete = Lvx & Lvy;
figure
plot(X, Y)
hold on
plot(Zx, Zy)
hold off
grid
figure
plot(X(~RowsToDelete), Y(~RowsToDelete))
hold on
plot(Zx(~RowsToDelete), Zy(~RowsToDelete))
hold off
grid