Pages

21.6.11

Resample a Matrix in Matlab

This function does the same as the previous one (resample) but for a matrix. Again, maybe not the most elegant, but works


function newmatrix=resampmatrix(matrix,newlen)

%----------------

%this function uses linear interpolation to change the number of rows in a

%matrix.

%Copyright, 2011, Andrés González


%----------------

[rows cols]=size(matrix);

newmatrix=[];

for i=1:cols

len=rows;

x=1:len;x=x';y=matrix(:,i);

xx=1:(len-1)/(newlen-1):len;

xx=xx';

yy=interp1(x,y,xx,'linear');

newmatrix=[newmatrix yy];

end

No comments:

Post a Comment