Zero padding in Matlab

I have an image and I want to make a selection. First of all, I need to connect zeros between pixels so that [1,2,3] is converted to [1,0,2,0,3]. Can anyone tell me how to do this without using paddarray

or using loops for


Thank you in advance!


source to share

4 answers

Something like that?:



However, there are ways to increase sampling in Matlab without having to do it manually, for example interp2



You can also use MATLAB's way of dynamically allocating variables if you don't specify a number for the index in the array. By disabling indexing to specific locations in your array, MATLAB fills those values ​​with zeros by default. Thus:

B(1:2:5) = 1:3

B = 

1   0   2   0   3




V = [1,2,3];

padded(numel(V)*2) = 0;
padded(1:2:end) = V


And then just handle the trailing zero if it numel(V)

was odd



There is a function upsample

that does exactly that from Octave-Forge - see the docs at upsample .

Or you can look at the sourceupsample

to see what implements it. Are you against using a package or feature?



All Articles