Thread Subject: Take non-zero values

Subject: Take non-zero values

From: M K

Date: 8 Nov, 2009 16:04:01

Message: 1 of 3

How does one remove zeros from an array of numbers. For example f

x=[0
0
0
0
1
2
3
0
0
0];


How can I get x to be

x=[1
2
3]

thanks

Subject: Take non-zero values

From: dpb

Date: 8 Nov, 2009 16:08:29

Message: 2 of 3

M K wrote:
> How does one remove zeros from an array of numbers. ...

x(x==0)=[];

Look up "logical addressing" in documentation...

--

Subject: Take non-zero values

From: Matt

Date: 8 Nov, 2009 17:03:01

Message: 3 of 3

"M K" <maha_k@mathworks.com> wrote in message <hd6q5h$ri9$1@fred.mathworks.com>...
> How does one remove zeros from an array of numbers. For example f
>
> x=[0
> 0
> 0
> 0
> 1
> 2
> 3
> 0
> 0
> 0];
>

x=nonzeros(x);

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com