[Scilab-users] Generating a boolean vector or matrix

Dang Ngoc Chan, Christophe Christophe.Dang at sidel.com
Wed Sep 4 09:49:24 CEST 2019


Hello,

> De : Federico Miyara
> Envoyé : mercredi 4 septembre 2019 09:11
>
> I need to create a boolean vector, such as [%t, %t, %t, %t] […] I
> couldn't find a function similar to ones(1,n).
>
> However I've found a workaround:
>
> a = ones(1,n) & %t
> […]
> 1) Why does it work?

Because "A number is considered as %F (false) if it is 0 or 0+0i. Otherwise (including %nan), it is equivalent to %T (true)."

https://help.scilab.org/docs/6.0.2/en_US/and.html

> 2) Is there some native function to create bolean matrices

No, but you have several other ways, you may test to find the one that is the less greedy.

I propose this one:

a = (ones(1,n) == 1)

Apart from this, I think most (if not all) functions that require boolean also accept numbers In the same way as and() (but I may be mistaken).

Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


More information about the users mailing list