[Scilab-users] Conditional assignments

Michael Dunn michael.dunn at ubm.com
Sun Apr 21 21:49:28 CEST 2013


Say I want to do an array (vector) assignment, but the formula requires a conditional. Is there a better way to do it than:

b = ((a^2).*(a<5)) + ((a^0.5).*(a>=5))

which returns a^2 for a<5, and sqrt(a) for a>=5.

And – just curious – if this is the only way, is the interpreter smart enough to not waste its time computing the false expression?


Thanks,


Michael Dunn | Editor-in-Chief
Scope Junction | http://www.scopejunction.com/
(415) 947-6096 (USA)
(519) 744-9395 (Canada)
Skype: MichaelDunn_UBM
LinkedIn: http://www.linkedin.com/in/cantares
[cid:F5B559D4-7097-437C-B95F-49FE1D296AA9]<http://www.tech.ubm.com/>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20130421/2bd60761/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0290B74A-5E6F-4D23-9C8D-ABE56804E06E[66].png
Type: image/png
Size: 6781 bytes
Desc: 0290B74A-5E6F-4D23-9C8D-ABE56804E06E[66].png
URL: <https://lists.scilab.org/pipermail/users/attachments/20130421/2bd60761/attachment.png>


More information about the users mailing list