Image Compression Using the Singular Value Decomposition (SVD) with MATLAB
If you look at the structure of your matrices of singular values S_R, S_G and S_B, you'll see that the non-zero entries lie on the diagonal. You can check only these entries by using diag, removing the need for your S_R&gt;0 condition.

This also means that for find you don't need to supply the second output argument.

To get the first non-zero entries less than sigma_threshold you can hence use

red_j = find(diag(S_R) &lt; sigma_threshold, 1);
green_j = find(diag(S_G) &lt; sigma_threshold, 1);
blue_j = find(diag(S_B) &lt; sigma_threshold, 1);


Bear in mind that this is the first value which should be cut off, not the last value to include, hence you might want to do

red_j = find(diag(S_R) &lt; sigma_threshold, 1) - 1;


or

red_j = find(diag(S_R) &gt;= sigma_threshold, 1, 'last');