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

Samuel Gougeon sgougeon at free.fr
Mon Jan 20 09:29:42 CET 2020


Le 20/01/2020 à 09:18, Federico Miyara a écrit :
>
> Dear All,
>
> I have an N-D array A (sometimes called hyperarray) with n dimensions, 
> where n is a parameter a priori unknown since it is, for instance, an 
> input argument of a function. So in conceptual form each element is
>
> A(k1, k2, k3, ..., kn)
>
> I'm looking for an elegant way to extract all elements with a given 
> index over a given dimension, for instance
>
> A(:, k2, :, ..., :)
>
> This would mean to get an hyperarray made up of the k2-th column of 
> all remaining dimensions.
>
> If extraction could be performed replacing the indexes by a list, for 
> instance
>
> L = list(),
> for i=1:n
>    L($+1) = 1:size(A)(i);
> end
> L(2) = 1
>
> Then A(L) would work, but the result is an error message "Invalid index".


A(L(:)) should do it.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20200120/6ff981e0/attachment.htm>


More information about the users mailing list