[Scilab-users] Accessing elements sharing an index from a diimension en N-D arrays

Federico Miyara fmiyara at fceia.unr.edu.ar
Fri Jan 24 02:47:08 CET 2020


Samuel,

Thank you for your very informative answer.

Regards,

Federico Miyara

On 23/01/2020 21:31, Samuel Gougeon wrote:
> Le 21/01/2020 à 00:54, Federico Miyara a écrit :
>>
>> Samuel,
>>
>> Thanks VERY much!
>>
>> It certainly does the job, but I don't quite understand how. For 
>> example, to retrieve the last columns of all dimensions:
>>
>>
>> A = matrix(1:120, [5,4,2 3]);
>>
>> L = list();
>> for i=1:length(size(A))
>>     L($+1) = 1:size(A)(i);
>> end
>>
>> L(2) = size(A)(2);
>
>
> // or
> L = list();
> for i = 1:ndims(A)
>     L($+1) = :;
> end
> L(2) = $;
>
>
>>
>> B = A(L(:));
>>
>> B is exactly the desiredresult. But when I try to see what is L(:) I get
>>
>> --> L(:)
>>  ans  =
>>
>>    1.   2.   3.   4.   5.
>
>
> Yes, it's a bit tricky: L(:) extracts all L components, but there is 
> no LHS recipient except the invisible ans. Then, only ans is assigned, 
> to L(1). Other L(2:$) are ignored.
>
>
>> .../...
>>
>> If I try to assign L(:) to a variable I get
>>
>> --> u=L(:)
>>
>> Can not assign multiple value in a single variable
>
>
> This is somewhat reported here: http://bugzilla.scilab.org/14372
>
>
>>
>> So I attempt
>>
>> --> [u1,u2,u3,u4] = L(:)
>>
>> and get
>>
>>
>>  u4  =
>>
>>    1.   2.   3.
>>  u3  =
>>
>>    1.   2.
>>  u2  =
>>
>>    4.
>>  u1  =
>>
>>    1.   2.   3.   4.   5.
>
>
> This is described on 
> https://help.scilab.org/docs/6.0.2/en_US/brackets.html
>
>
>>
>> ../..
>>
>> I would like to understand what's going on.
>
>
> (a,b,c) is the smart Scilab "deal()" operator:
>
> [a, b, c] = (3, 1, -2)
>
> --> [a, b, c] = (3, "Hi", -2)
>  a  =
>   3.
>
>  b  =
>   Hi
>
>  c  =
>    -2
>
> Regards
> Samuel
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20200123/2a48f342/attachment.htm>


More information about the users mailing list