Prev: interrupting a running script
Next: MATLAB FFT and IFFT
From: Pink Panther on 15 Jun 2010 15:49 hi, sorry for posting such basic questions, here we go : 1. some of my m files / folders show a small lock attached to the matlab icon, and do not appear when I search them in a window explorer window. how can I change this property? 2. I'd like to calculate the median of a vector, excluding all the 0 in the vector. in other words the median of non 0 data points. how can I do that without the heavy solution of creating a vector with only non 0 elements and then calculating the median of this second vector ? many thanks in advance
From: us on 15 Jun 2010 17:03 "Pink Panther " <huguesrialan(a)gmail.com> wrote in message <hv8lfi$bnp$1(a)fred.mathworks.com>... > hi, sorry for posting such basic questions, here we go : > > 1. some of my m files / folders show a small lock attached to the matlab icon, and do not appear when I search them in a window explorer window. how can I change this property? > > 2. I'd like to calculate the median of a vector, excluding all the 0 in the vector. in other words the median of non 0 data points. how can I do that without the heavy solution of creating a vector with only non 0 elements and then calculating the median of this second vector ? > > many thanks in advance one of the many solutions v=[0,0,1,0,2,0]; r=median(v(v~=0)) % r = 1.5 us
From: Roger Stafford on 15 Jun 2010 17:06 "Pink Panther " <huguesrialan(a)gmail.com> wrote in message <hv8lfi$bnp$1(a)fred.mathworks.com>... > hi, sorry for posting such basic questions, here we go : > > 1. some of my m files / folders show a small lock attached to the matlab icon, and do not appear when I search them in a window explorer window. how can I change this property? > > 2. I'd like to calculate the median of a vector, excluding all the 0 in the vector. in other words the median of non 0 data points. how can I do that without the heavy solution of creating a vector with only non 0 elements and then calculating the median of this second vector ? > > many thanks in advance For 2. m = median(v(v~=0)); This is deceptive however. You may be sure that somewhere an intermediate vector containing only the nonzero elements of v is created before the median is computed. But one line makes it look nice. In any case, the median operation probably takes the lion's share of cpu time. Roger Stafford
From: Bruno Luong on 15 Jun 2010 17:16 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hv8pvu$qc0$1(a)fred.mathworks.com>... > In any case, the median operation probably takes the lion's share of cpu time. It's surely not optimally implemented in Matlab with sorting. The median could be retrieve in linear time. Bruno
From: Roger Stafford on 15 Jun 2010 18:30
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hv8qik$5fk$1(a)fred.mathworks.com>... > "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hv8pvu$qc0$1(a)fred.mathworks.com>... > > In any case, the median operation probably takes the lion's share of cpu time. > > It's surely not optimally implemented in Matlab with sorting. The median could be retrieve in linear time. > > Bruno You are right about that Bruno (as usual.) The recursive "median of the medians" algorithm, (which I've only just now become aware of,) can make it order N, though it is a rather complicated affair. I wonder if Mathworks has actually implemented such an algorithm in their 'median' routine. I still think it would take considerably more cpu time than the intermediate step of simply constructing a temporary vector of non-zeros in this problem, at least for long vectors. Roger Stafford |