 | | From: | supra | | Subject: | Remove zeros in a matrix | | Date: | Mon, 24 Jan 2005 04:08:40 +0000 (UTC) |
|
|
 | I have generated several elements in a Matrix as follows:
A= [ 0 0 0 0 0 7 8 9 0 0 0 0 0]
but I require the final answer as
A=[7 8 9]
How do I remove the the zeros in the matrix?
Please advise
Regards
Supramaniam
|
|
 | | From: | Derek Goring | | Subject: | Re: Remove zeros in a matrix | | Date: | 23 Jan 2005 20:40:26 -0800 |
|
|
 | supra wrote: > I have generated several elements in > a Matrix as follows: > > A= [ 0 0 0 0 0 7 8 9 0 0 0 0 0] > > but I require the final answer as > > A=[7 8 9] > > How do I remove the the zeros in the matrix? > > Please advise > > Regards > > > Supramaniam
A(A~=0)
|
|
 | | From: | Fijoy George | | Subject: | Re: Remove zeros in a matrix | | Date: | Sun, 23 Jan 2005 23:42:19 -0500 |
|
|
 | Why dont you just write a loop and filter the non-zero elements of A into a new matrix B?
-Fijoy
"supra" wrote in message news:j8i8bslzjcku@legacy... > > I have generated several elements in > a Matrix as follows: > > A= [ 0 0 0 0 0 7 8 9 0 0 0 0 0] > > but I require the final answer as > > A=[7 8 9] > > How do I remove the the zeros in the matrix? > > Please advise > > Regards > > > Supramaniam >
|
|
 | | From: | Johan Carlson | | Subject: | Re: Remove zeros in a matrix | | Date: | Mon, 24 Jan 2005 08:05:16 +0100 |
|
|
 | Fijoy George wrote:
> Why dont you just write a loop and filter the non-zero elements of A into a > new matrix B? > > -Fijoy >
No! Don't use a loop. Use the solution proposed by Derek instead. Loops are generally a very bad idea in MATLAB and should be used only when nothing else is possible.
/Johan
> "supra" wrote in message > news:j8i8bslzjcku@legacy... > >> I have generated several elements in >> a Matrix as follows: >> >> A= [ 0 0 0 0 0 7 8 9 0 0 0 0 0] >> >> but I require the final answer as >> >> A=[7 8 9] >> >> How do I remove the the zeros in the matrix? >> >> Please advise >> >> Regards >> >> >> Supramaniam >> > > >
|
|