Prev: Can't seem to get any functions to work in 7.8.0 Student
Next: if d = x^2, and x=[0,0;1,0] then why is eval(d) not equal to
From: jacob cohen on 27 Mar 2010 15:43 I would like to write a fast program which sets all negative values in an array to zero. I have tried this using two for loops an an if statement but it is way too slow for my large array sizes. My arrays are 5000 x 600, so I need something better than what I have. I have thought about using the find function but I haven't tried that yet. Are there any built in functions which would do this for me?? Thanks, Jake
From: us on 27 Mar 2010 15:48 "jacob cohen" <jcohen7(a)gatech.edu> wrote in message <holn46$1ru$1(a)fred.mathworks.com>... > I would like to write a fast program which sets all negative values in an array to zero. I have tried this using two for loops an an if statement but it is way too slow for my large array sizes. My arrays are 5000 x 600, so I need something better than what I have. > > I have thought about using the find function but I haven't tried that yet. Are there any built in functions which would do this for me?? > > Thanks, > Jake one of the many solutions v=[-1,2,-3,4,0,-5,6]; v(v<0)=0 % v = 0 2 0 4 0 0 6 us
From: Walter Roberson on 27 Mar 2010 18:23
jacob cohen wrote: > I would like to write a fast program which sets all negative values in > an array to zero. A = max(0,A); |