MATLAB: How to filter data in a variable based on its value

arraycellfunindexMATLAB

Hello,
I have one 100 by 3 array which contains random values from 0 to 1000
I wanted to filter the data in a new array so that only values above 500 are shown.
To do this I did
A = randi([0 1000],100,3) %Generates random numbers from 0 to 1000 in a 100by3 array
A(A>500) %This is the area I need help
In the code above, A(A>500) only shows me values from the first column of A which are greater than 500.
How can I extend this so that A(A>500) will generate a x by 3 array?

Best Answer

This will set the elements that are less than or equal to 500 to 0:
A = A.*(A>500);
It preserves the structure of ‘A’.