|
On Oct 21, 3:19 am, "Ci Griaal" <cigri...@yahoo.com.au> wrote:
> Hi
> I've written a very simple code that samples a random numbers from a normal distribution using a different mean and standard deviation at each time. It also substitute the negative values by zero.
>
> load('.\data');
> randn('state',sum(100*clock));
> for i=1:length(x)
> z(i) = ( randn(1,1) * x(i) ) + y(i);
> if z(i)<0;
> z(i)=0;
> end
> end
>
> In which data.mat contains two .mat with single columns (x and y)
> The code works well, however I am dealing with huge files and really need to run it quicker. I know I can improve the performance using
> i=1:length(x)
> z = ( randn(1,1) * x ) + y
>
> instead of the for loop, but I don’t know how to deal with the if in this case.
> Any tips please?
On a side note, because you are replacing negative values with 0, you
should know that the values you are generating then don't come from
the normal distribution anymore... (at least in a strict sense).
best, arun.
|