MATLAB: Eliminating Matrix Elements Which Exceeds Some Threshold with Using idx

eliminating matrix elementsrelevant points

I am working on a Radon transform algorithm, in my code i have a set of x,y values and i wanted to eliminate the x,y values which exceeds some certain values like -2 and 2 for example. For this purpose, i am using the code below but i couldn't get how it works. Is there anyone who can explain to me?
idx=any(A<-M/2 | A>M/2,2);
out=A(idx,:);
A(idx,:)=[];
Thanks in advance.

Best Answer

A is a Matrix of m rows by n columns, therefore, idx is going to be a logical vector of m rows by 1 column, if any element in the row of A is less than -M / 2 or greater than M / 2 then in that row the idx value will be 1 otherwise it will be 0.
in out those rows of A that were positive in idx are going to be saved and from those rows we want to get all the columns, and after that in those same rows that were 1 with A (idx,:) = []; what is done is to eliminate them and have a new Matrix of A without those rows.
Related Question