[Scilab-users] Regarding simple numerical operations result display.

Stefan Du Rietz sdr at durietz.se
Sun Mar 17 22:24:40 CET 2013


But this is the ultimate solution without a loop:

-->bool2s(y>a) .* b + bool2s(~y>a) .* y
  ans  =
   - 11.  - 6.  - 1.    4.    100.

/Stefan

On 2013-03-17 22:05, Stefan Du Rietz wrote:
--------------------
> Maybe one of the last two of these four loops was what you wanted:
>
> -->bool2s(y>a)
>   ans  =
>      0.    0.    0.    0.    1.
>
> -->for k=bool2s(y>a), if k, disp(b), else, disp(y), end, end
>    - 11.  - 6.  - 1.    4.    9.
>    - 11.  - 6.  - 1.    4.    9.
>    - 11.  - 6.  - 1.    4.    9.
>    - 11.  - 6.  - 1.    4.    9.
>      100.
>
> -->for k=y, if k>a, disp(b), else, disp(y), end, end
>    - 11.  - 6.  - 1.    4.    9.
>    - 11.  - 6.  - 1.    4.    9.
>    - 11.  - 6.  - 1.    4.    9.
>    - 11.  - 6.  - 1.    4.    9.
>      100.
>
> Here, k takes the value of each element in y:
>
> -->for k=y, if k>a, disp(b), else, disp(k), end, end
>    - 11.
>    - 6.
>    - 1.
>      4.
>      100.
>
> Or maybe this is easier to follow:
>
> -->for k=1:length(y), if y(k)>a, disp(b), else, disp(y(k)), end, end
>    - 11.
>    - 6.
>    - 1.
>      4.
>      100.
>
> /Stefan
>
> On 2013-03-17 20:46, Stefan Du Rietz wrote:
> --------------------
>> Sorry,
>> I should have written (?):
>>
>> A multi-element logical array is true (T) only if all elements are T.
>> -->and(y>a)
>>   ans  =
>>    F
>>
>> /Stefan
>>
>> On 2013-03-17 20:35, Stefan Du Rietz wrote:
>> --------------------
>>> -->y=(5*x)-1
>>>   y  =
>>>    - 11.  - 6.  - 1.    4.    9.
>>>
>>> -->y>a
>>>   ans  =
>>>    F F F F T
>>>
>>> This is F (the first element)
>>>
>>> /Stefan
>>>
>>>
>>> On 2013-03-17 20:23, Modestas Bunokas wrote:
>>> --------------------
>>>> If someone will find 2 min of free time, I would be very grateful.
>>>> I'm
>>>> somehow getting weird result doing simple operation like:
>>>>
>>>> a=7;  b=100;  x=[-2:1:2];  y=(5*x)-1;
>>>> if  y>a  then  disp(b);
>>>>      else  disp(y);
>>>> end
>>>>
>>>> --> - 11.  - 6.  - 1.    4.    9.
>>>>
>>>> Last result (9) is wrong, it should be 100 (b). I fully understand
>>>> that it's because of lack of my knowledge in programming but in few
>>>> days I could not solve or even could not find any help. Because of
>>>> that writing here.
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>




More information about the users mailing list