【发布时间】:2012-02-08 15:08:51
【问题描述】:
我有一个存储 x、y 和 z 值的矩阵:
{x1, y1, z1},
{x2, y2, z2},
{x3, y3, z3},
etc...
我需要对数据进行插值,并绘制在二维图表上,颜色代表 z 值。 (example)
有什么想法吗?
谢谢!
【问题讨论】:
标签: matlab graph multidimensional-array 2d
我有一个存储 x、y 和 z 值的矩阵:
{x1, y1, z1},
{x2, y2, z2},
{x3, y3, z3},
etc...
我需要对数据进行插值,并绘制在二维图表上,颜色代表 z 值。 (example)
有什么想法吗?
谢谢!
【问题讨论】:
标签: matlab graph multidimensional-array 2d
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
【讨论】:
除了@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); 将其转换为数值矩阵
【讨论】: