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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com