[Scilab-users] range of colon
Samuel Gougeon
sgougeon at free.fr
Wed Jan 15 01:35:50 CET 2020
Le 14/01/2020 à 22:40, Federico Miyara a écrit :
>
> Dear all,
>
> I need to zero-pad the columns of an N-D array x to a length N. I've
> found the following solution:
>
> siz = size(x);
> a = repmat(0,[N, siz(2:$)]); // Create array of 0's whose columns
> have length N
> // and the remaining dimensions are
> the same as in x
> a(1:siz(1), :) = x; // Replace non-padding 0's by x
>
>
> This seems to work.
Really?:
--> x = rand(3,4,2);
--> N= 5;
--> siz = size(x);
--> a = repmat(0,[N, siz(2:$)]); // Create array of 0's whose
columns have length N
--> a(1:siz(1), :) = x
Submatrix incorrectly defined.
Why not using resize_matrix()?
s = size(a);
x = resize_matrix(x,[N, s(2:$)]);
--> resize_matrix(x,[N s(2:$)])
ans =
(:,:,1)
0.3616361 0.4826472 0.5015342 0.6325745
0.2922267 0.3321719 0.4368588 0.4051954
0.5664249 0.5935095 0.2693125 0.9184708
0. 0. 0. 0.
0. 0. 0. 0.
(:,:,2)
0.0437334 0.4148104 0.7783129 0.6856896
0.4818509 0.2806498 0.211903 0.1531217
0.2639556 0.1280058 0.1121355 0.6970851
0. 0. 0. 0.
0. 0. 0. 0.
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20200115/42c7ec72/attachment.htm>
More information about the users
mailing list