今天有个小需求需要要进行插值,网上的资料都不是特别好,经过自己摸索,最终搞定。 以后要熟悉meshgrid和linspace的用途,我觉得还蛮重要的
直接上matlab code吧,经过调试没问题,这个相当于是一个小笔记吧
clc
close allclear all
matrix = rand(10,12);
[rows,cols] = size(matrix);
[x,y]=meshgrid(1:1:rows,1:1:cols);
[xi,yi] = meshgrid(1:0.5:rows+0.5,1:0.5:cols+0.5); % after interpolation, the size will be two times.
zi = interp2(x,y,matrix',xi,yi,'cubic'); % remember the matrix must be transposed matrix'
% now zi is cols*rows pare careful to such issue
figure(1);
surfc(xi,yi,zi)
colorbar
xlabel('x'),ylabel('y');