MATLAB: Changing values in 2D array using logical operators

2darraylogical?MATLABsubselect

I'm sure I've solved this before, but it's befuddled me today.
I have a 2D array and I want to subselect some values and set them to nan:
aa=rand(10,10);
ab(aa<0.5)=nan;
ab is now a 1×100 row vector – how can I perform the operation but maintain the 2D array?

Best Answer

aa = rand(10, 10);
aa(aa < 0.5) = NaN;
Related Question