|
Hi Florin,
Thanks for the response, I've just seen it now. I haven't used profiler before, can you point me in the direction of some good literature on it? I might try check it out.
I'll try the method you have mentioned below with tic toc and see if it improves performance.
Thanks for the help
"Florin Neacsu" <fneacsu2@gmail.com> wrote in message <in2a0p$p08$1@fred.mathworks.com>...
> "david " <davidtra84@gmail.com> wrote in message <in1e65$s00$1@fred.mathworks.com>...
> > Hi, I'm relatively new to matlab and just looking for some help in speeding up the process below. I believe that the for loop is what is causing the problem & would appreciate any help/input that could help speed up the process.
> >
> > for the variables:
> > z is a single column vector ranging from -100 to +100 in a random order.
> > r=70;
> > y=45;
> >
> > x=[-abs(z>r) , abs(z<-r)];
> > x=x(:,1)+x(:,2);
> >
> > for i=1:length(x)-1;
> > if x(i)<0 && z(i+1)<y;
> > x(i+1)=-1;
> > elseif x(i)>0 && z(i+1)>-y;
> > x(i+1)=1;
> > end
> > end
> >
> > Thanks in advance.
>
>
> Hi,
>
> Maybe something like this ?
>
> temp11=x<0;
> temp12=z<y;
> x(find(temp11(1:end-1).*temp12(2:end))+1)=-1;
>
> temp21=x>0;
> temp22=z>-y;
> x(find(temp21(1:end-1).*temp22(2:end))+1)=1;
>
>
> But to be honest I do not know if it speeds things up. Do you know how to use profiler? Or you could also try tic .... toc and get a sense if it works or not.
>
> Hope it helps.
> Regards,
> Florin
|