I have a long vector, containing > 1 million entries, distributed according to a probability density function (Gaussian). I only need the positive values, and these I find as in the following MWE
N = 1.5e6;
vals = normrnd(0, 1, N, 1);
final = [];
for i=1:length(vals)
if(vals(i)>0)
final = [final vals(i)];
end
end
The problem is that this takes a long time. Is there a smarter way to do this in MatLAB?
Thanks,
Niles.
You can remove the negative numbers without a for loop in matlab: