[Scilab-users] range of colon
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. However, I'm concerned about the use of the last : as a replacemant for all the remaining dimensions, since I couldn't find it documented. Is it an intended behviour? Regards, Federico Miyara ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] range of colon
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 ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] range of colon
Samuel, 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. It worked for size (8,1,3). It shouldn't work either, but somehow it does... Why not using resize_matrix()? Thanks! It is exactjy what I needed, only I was not aware of its existence! Regards, Federico Miyara ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users