Zeropad a matrix in matlab

129 Views Asked by At

I'm having a signal y of 52989 x 2 values. What I want to do is zero pad it until I get like signal y_mp3 66379 x 2. Here a sample of my code:

P = 13750
y= [zeros(1,P),w];

I constantly receive the error: dimensions of matrices being concatenated are not consistent. I tried to switch the 1 and P or the 2 arguments but stil no good. Can someone clarify my error?

EDIT: I tried following suggestion but still the same:

P = length(y)-length(y_mp3);
y_mp3_p = y_mp3;
padsize = P / 2;
padarray(y_mp3_p, [padsize 0]);

Thanks in advance everyone!

2

There are 2 best solutions below

3
mehmet On

You can use MATLAB padarray() function. The code below may work:

padsize = p / 2;
padarray(w, [padsize 0]);

or,

p = 13750;
padarray(w, [p 0],'pre');
1
user3488736 On

Thanks to Mehmet I finally found it! It should be:

P = size(y,1) - size(y_mp3,1);
padsize = P/2 ;
y_p = padarray(y_mp3, [padsize 0],'sym');