[Scilab-users] Conditional assignments

Stefan Du Rietz sdr at durietz.se
Sun Apr 21 23:34:31 CEST 2013


You can combine several index vectors with & and/or(!) |

You can also shift one e.g. to get the preceding elements:
[index(2:$) %f]

Use your imagination ;-)

Regards
Stefan


On 2013-04-21 22:42, Michael Dunn wrote:
> Very cool. What other tricks can one do with %t & %f?
>
> 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
>   <http://www.tech.ubm.com/>
>
>
>
>
>
>
> -----Original Message-----
> From: Stefan Du Rietz <sdr at durietz.se>
> Reply-To: "International users mailing list for Scilab."
> <users at lists.scilab.org>
> Date: Sunday, April 21, 2013 4:28 PM
> To: "International users mailing list for Scilab." <users at lists.scilab.org>
> Subject: Re: [Scilab-users] Conditional assignments
>
>> If the interpreter is not smart enough and the vector is large, maybe
>> this is faster -- only one computation/element:
>>
>> index = a<5;
>> b = zeros(a);
>> b(index) = a(index)^2;
>> b(~index) = a(~index)^0.5;
>>
>> /Stefan
>>
>>
>> On 2013-04-21 21:49, Michael Dunn wrote:
>> --------------------
>>> 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
>>> <http://www.tech.ubm.com/>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> users mailing list
>>> users at lists.scilab.org
>>> http://lists.scilab.org/mailman/listinfo/users
>>>
>>
>>
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> http://lists.scilab.org/mailman/listinfo/users
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>




More information about the users mailing list