getting masks

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

getting masks

Artur Jorge Azevedo Carvalho
hi! how can i do in an oct file the following:
a=[
1.1 1.2 3.2
1.4 0.0 2.3
6.3 -5.1 1.1
]
a!=0 to give
[
1 1 1
1 0 1
1 1 1
]

the best way i've found to do this was:
a=Matrix(!!a);

to give the same result, but it has to exist a better way to do this...

thks in advance...


Reply | Threaded
Open this post in threaded view
|

getting masks

Dirk Eddelbuettel

  Artur Jorge Azevedo Carvalho writes:
  Artur>  hi! how can i do in an oct file the following: a=[ 1.1 1.2 3.2 1.4
  Artur> 0.0 2.3 6.3 -5.1 1.1 ] a!=0 to give [ 1 1 1 1 0 1 1 1 1 ]
  Artur>
  Artur> the best way i've found to do this was: a=Matrix(!!a);
  Artur>
  Artur> to give the same result, but it has to exist a better way to do
  Artur> this...

Use  a != 0 as here:

edd@sonny:~> octave
GNU Octave, version 2.0.14 (i386-pc-linux-gnu).
Copyright (C) 1996, 1997, 1998, 1999 John W. Eaton.
This is free software with ABSOLUTELY NO WARRANTY.
For details, type `warranty'.

octave:1> a=[1.1 1.2 3.2; 1.4 0.0 2.3; 6.3 -5.1 1.1];
octave:2> b=a!=0
b =

  1  1  1
  1  0  1
  1  1  1
                             

--
According to the latest figures, 43% of all statistics are totally worthless.


Reply | Threaded
Open this post in threaded view
|

Re: getting masks

Artur Jorge Azevedo Carvalho


Dirk Eddelbuettel wrote:

>   Artur Jorge Azevedo Carvalho writes:
>   Artur>  hi! how can i do in an oct file the following: a=[ 1.1 1.2 3.2 1.4
>   Artur> 0.0 2.3 6.3 -5.1 1.1 ] a!=0 to give [ 1 1 1 1 0 1 1 1 1 ]
>   Artur>
>   Artur> the best way i've found to do this was: a=Matrix(!!a);
>   Artur>
>   Artur> to give the same result, but it has to exist a better way to do
>   Artur> this...
>
> Use  a != 0 as here:
>
> edd@sonny:~> octave
> GNU Octave, version 2.0.14 (i386-pc-linux-gnu).
> Copyright (C) 1996, 1997, 1998, 1999 John W. Eaton.
> This is free software with ABSOLUTELY NO WARRANTY.
> For details, type `warranty'.
>
> octave:1> a=[1.1 1.2 3.2; 1.4 0.0 2.3; 6.3 -5.1 1.1];
> octave:2> b=a!=0
> b =
>
>   1  1  1
>   1  0  1
>   1  1  1
>
>
> --
> According to the latest figures, 43% of all statistics are totally worthless.

  in command line i know how to do it but i'm asking in a .oct file....
and the solution i provided works, but i'm asking if there is a better
way to do it... cause this way i need to do two operations...




Reply | Threaded
Open this post in threaded view
|

getting masks

John W. Eaton-6
In reply to this post by Artur Jorge Azevedo Carvalho
On 24-May-1999, Artur Jorge Azevedo Carvalho <[hidden email]> wrote:

| hi! how can i do in an oct file the following:
| a=[
| 1.1 1.2 3.2
| 1.4 0.0 2.3
| 6.3 -5.1 1.1
| ]
| a!=0 to give
| [
| 1 1 1
| 1 0 1
| 1 1 1
| ]
|
| the best way i've found to do this was:
| a=Matrix(!!a);
|
| to give the same result, but it has to exist a better way to do this...

There is no special function for this in the 2.0.x Octave sources.
You have to use loops.

jwe