Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
2 basic questions : 'lock' and 'median'

Subject: 2 basic questions : 'lock' and 'median'

From: Pink Panther

Date: 15 Jun, 2010 19:49:06

Message: 1 of 6

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

Subject: 2 basic questions : 'lock' and 'median'

From: us

Date: 15 Jun, 2010 21:03:06

Message: 2 of 6

"Pink Panther " <huguesrialan@gmail.com> wrote in message <hv8lfi$bnp$1@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

Subject: 2 basic questions : 'lock' and 'median'

From: Roger Stafford

Date: 15 Jun, 2010 21:06:06

Message: 3 of 6

"Pink Panther " <huguesrialan@gmail.com> wrote in message <hv8lfi$bnp$1@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

Subject: 2 basic questions : 'lock' and 'median'

From: Bruno Luong

Date: 15 Jun, 2010 21:16:04

Message: 4 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hv8pvu$qc0$1@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

Subject: 2 basic questions : 'lock' and 'median'

From: Roger Stafford

Date: 15 Jun, 2010 22:30:27

Message: 5 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hv8qik$5fk$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hv8pvu$qc0$1@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

Subject: 2 basic questions : 'lock' and 'median'

From: Pink Panther

Date: 16 Jun, 2010 09:20:21

Message: 6 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hv8uu2$5dk$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hv8qik$5fk$1@fred.mathworks.com>...
> > "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hv8pvu$qc0$1@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


thanks guys, very instructive on points not even thought about initially, as always.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us