本帖最后由 meatball1982 于 2017-11-18 09:56 编辑
在matlab当中,默认的和你的效果是一样的。
我的思路是将x,y作一个小平移,每个都 -0.5.在新的x,y,z边上加一行和列,形成一个新的x,y,z.
以相同的方式画图。
如果可行,gnuplot 应该也可以实现。
主函数
- clear all
- clc
- [x,y,z]=peaks(10);
- z(1:2,:)=[];
- [x,y,z_new]=fun_mm_shift(z);
- subplot(1,2,1)
- surf(z)
- axis equal
- axis tight
- view(0,90)
- colorbar
- title('your fig')
- subplot(1,2,2)
- surf(x,y,z_new)
- colormap(hot)
- axis equal
- axis tight
- view(0,90)
- colorbar
- title('ref fig')
复制代码
平移的函数。要存成fun_mm_shift.m放在主函数的目录下,或是放在你matlab知道的路径里。
- function [ X,Y,z_new ] = fun_mm_shift( z )
- % [ X,Y,z_new ] = fun_mm_shift( z )
- % shfit the x,y to x-0.5, y-0.5
- % add one row and one column
- % for surf,
- [m,n]=size(z);
- [X,Y]=meshgrid([1:(n+1)]-0.5,[1:(m+1)]-0.5);
- tm=z;
- tm=[z;z(end,:)];
- z_new=[tm';tm(:,end)']';
- end
复制代码
|