我有3个系列数据: A = [1,1,1,1,2,2,3]; B = [52.97,52.92,51.78,55.66,50.45,50.23,53.02]; C = [0.7,0.7,0.7,0.7,0.8,0.8,0.5];
我想通过MATLAB通过这些数据绘制一个表面(C vs A和B);我怎样才能做到这一点?
当我使用“[A,B,C] = meshgrid(a,b,c); surf(A,B,C)”时,MATLAB会出错。请帮帮我。
答案 0 :(得分:1)
函数griddata()
可能会有所帮助。此功能可对3D空间中的散点进行插值。以下是使用三个向量a
,b
和c
应用于您的示例的用法示例:
%generate a new mesh over coordinates a and b
st_a=(max(a)-min(a))/50;
st_b=(max(b)-min(b))/50;
[xq,yq]=meshgrid(min(a):st_a:max(a),min(b):st_b:max(b));
%do interpolation for c over the new mesh
vq = griddata(a,b,c,xq,yq);
%plot the surface
surf(xq,yq,vq)
答案 1 :(得分:0)
您还可以使用scatteredInterpolant
不仅可以插入数据,还可以对其进行外推。但是,您没有足够的数据点来进行有意义的插值/外推。
a=[1,1,1,1,2,2,3].';
b=[52.97,52.92,51.78,55.66,50.45,50.23,53.02].';
c=[0.7,0.7,0.7,0.7,0.8,0.8,0.5].';
F = scatteredInterpolant(a,b,c);
da = (max(a)-min(a))/100;
db = (max(b)-min(b))/100;
ta = min(a):da:max(a);
tb = min(b):db:max(b);
[aq,bq] = meshgrid(ta,tb);
cq = F(aq,bq);
figure
mesh(aq,bq,cq);
hold on;
plot3(a,b,c,'o');
hold off;