我有一个存储x,y和z值的矩阵,如下所示:
{x1, y1, z1},
{x2, y2, z2},
{x3, y3, z3},
etc...
我需要插入数据,并在2d图上绘图,颜色代表z值。 (example)
有什么想法吗?
谢谢!
答案 0 :(得分:2)
griddata
之类的内容可能会帮助您进行插值:
x = vector(:,1);
y = vector(:,2);
z = vector(:,3);
% Settings
xres = 800; % Resolution, the higher, the smoother
yres = 800;
cm = 'default'; % Colormap
% Axes Limits
xmin = min(x);
ymin = min(y);
xmax = max(x);
ymax = max(y);
xi = linspace(xmin, xmax, xres);
yi = linspace(ymin, ymax, yres);
% Figure
myfig = figure('Position', [200 200 800 600]);
rotate3d off
[XI, YI] = meshgrid(xi, yi);
ZI = griddata(x, y, z, XI, YI, 'cubic');
mesh(XI,YI,ZI);
比你只需要更改它的视图只显示某个plane
的固定值z
答案 1 :(得分:2)
除了@Alexandrew answer,你可以使用更新更快的TriScatteredInterp类而不是GRIDDATA。对于您的示例,您可以使用2D IMAGESC而不是3D MESH。
%# insert the code from @Alexandrew answer to generate meshgrid
[XI, YI] = meshgrid(xi, yi);
TSI = TriScatteredInterp(x,y,z);
ZI = TSI(XI,YI);
imagesc(ZI)
colorbar
如果您的输入矩阵是单元格数组,则可以使用a = cell2mat(a);