[Scilab-users] Padarray Matlab equivalent in Scilab

Samuel Gougeon sgougeon at free.fr
Wed Feb 10 11:02:41 CET 2016


Hello,

Le 10/02/2016 09:49, Lester Anderson a écrit :
> Hi all,
>
> A quick one. I am looking for the Scilab equivalent to padarray in Matlab.
>
> In the Matlab code the line is:
> datapad = padarray(data, [rdiff cdiff], 'replicate') where cdiff/rdiff
> are column/row, with the replicate function padding with the values at
> the borders of "data"
>
> The closest I can find in Scilab is: resize_matrix
> resMat = resize_matrix(mat, nbRows, nbCols, resType, padding)
>
> Just want to verify I am looking at the correct option.
There is no real Scilab equivalent. Scilab's repmat() could be extended.
For the time being, to process, you may use the 2 following lines:

tmp = [data ; data($, :) .*. ones(addedRows, 1)];
paddedMat = [tmp  tmp(:, $) .*. ones(1,addedCols)];

// EXAMPLE:
addedRows = 3; addedCols = 2;
data = grand(4,3,"uin",-9,9)
tmp = [data ; data($, :) .*. ones(addedRows, 1)];
paddedMat = [tmp  tmp(:, $) .*. ones(1,addedCols)]

--> addedRows = 3; addedCols = 2;
--> data = grand(4,3,"uin",-9,9)
  data  =
   -5.  -1.  -7.
   -7.   3.  -4.
   -4.   3.   2.
    7.   2.   9.

--> tmp = [data ; data($, :) .*. ones(addedRows, 1)];

--> paddedMat = [tmp  tmp(:, $) .*. ones(1,addedCols)]
  paddedMat  =
   -5.  -1.  -7.  -7.  -7.
   -7.   3.  -4.  -4.  -4.
   -4.   3.   2.   2.   2.
    7.   2.   9.   9.   9.
    7.   2.   9.   9.   9.
    7.   2.   9.   9.   9.
    7.   2.   9.   9.   9.

HTH
Samuel Gougeon




More information about the users mailing list