MATLAB: Interpolating data in a better way

interp1interpolation

I will simplify this down, as my data is huge. I have about 100 sets of data smaller than the one I am going up to; each one of them vary in size. IE 3×6 or 9×9. I need to interpolate it up to say 20×20. Names of variables were changed for simplicity also.
A 3×3 raw data would look like this, and cannot change (easily) as I am importing from an edit locked file.
rawdata=[1 7 3 ;8 9 6; 2 2 5];
Here is how am currently going about it.
g_raw = size(rawdata);
xg_g = linspace(1,20,g_raw(1));
yg_g = linspace(1,20,g_raw(2));
interp_x_g = interp1(xg_g, g_raw, 1:20); %doing one direction
interp_y_g = interp1(yg_g, interp_x_g', 1:20)'; %tackling other direction with a transpose and transpose back
interpolated_g = interp_y_g(:); %making into a vector for plotting vs another vector
It works in a sense, but comes out very choppy. Is there a better way? I have been using MatLab for about a week and getting the hang of it. I just do not understand everything in the help files. IE I could not get polyfit to work in my loops. Not sure if I should be using interp2 or 3? All help is appreciated, even if it is just correcting syntax or general advice.
Cheers!
Walt

Best Answer

Yeah, try interp2 -- sotoo
[nr,nc]=size(rawdata);
[X,Y] = meshgrid(1:nr,1:nc); % the original array mesh
[Xq,Yq] = meshgrid(linspace(1,nr,20),linspace(1,nr,20)); % the 20X copy
Vq = interp2(X,Y,rawdat,Xq,Yq);
Related Question