MATLAB:将 3d 表面拟合到条形图
MATLAB: fitting a 3d surface to a bar graph
我有一个由 0 到 1 之间的数字组成的矩阵(大约 400x400)。这是 3D 条形图的绘图
我想使 3D 表面适合条形图。有任何想法吗?矩阵的元素(0 到 1 之间的数字)应给出每个索引处的表面高度。我希望表面只是给我们条形图的一般形状,而不是遍历每个点。
% init
x = randn(1000,1);
y = randn(1000,1);
nbins = [10 20];
% make histogram
h = histogram2(x,y,nbins)
% set limits and steps
min_x = min(x); max_x = max(x); step_x = (max_x - min_x)/nbins(1);
min_y = min(y); max_y = max(y); step_y = (max_y - min_y)/nbins(2);
% make grid
surf_z = h.Values;
surf_x = [min_x + step_x/2 : step_x : max_x - step_x/2];
surf_y = [min_y + step_y/2 : step_y : max_y - step_y/2];
[xx, yy] = meshgrid(surf_x, surf_y)
% plot 3D surface
surf(xx',yy',surf_z)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% other variant
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% make grid and interpolant
[xx, yy] = ndgrid(surf_x, surf_y)
F = griddedInterpolant(xx,yy,surf_z,'spline');
% make 3D surface with a some step value
step = 0.01;
[Xq,Yq] = ndgrid(min(surf_x):step:max(surf_x), min(surf_y):step:max(surf_y));
Zq = F(Xq,Yq);
% plot 3D surface
mesh(Xq,Yq,Zq);
我有一个由 0 到 1 之间的数字组成的矩阵(大约 400x400)。这是 3D 条形图的绘图
我想使 3D 表面适合条形图。有任何想法吗?矩阵的元素(0 到 1 之间的数字)应给出每个索引处的表面高度。我希望表面只是给我们条形图的一般形状,而不是遍历每个点。
% init
x = randn(1000,1);
y = randn(1000,1);
nbins = [10 20];
% make histogram
h = histogram2(x,y,nbins)
% set limits and steps
min_x = min(x); max_x = max(x); step_x = (max_x - min_x)/nbins(1);
min_y = min(y); max_y = max(y); step_y = (max_y - min_y)/nbins(2);
% make grid
surf_z = h.Values;
surf_x = [min_x + step_x/2 : step_x : max_x - step_x/2];
surf_y = [min_y + step_y/2 : step_y : max_y - step_y/2];
[xx, yy] = meshgrid(surf_x, surf_y)
% plot 3D surface
surf(xx',yy',surf_z)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% other variant
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% make grid and interpolant
[xx, yy] = ndgrid(surf_x, surf_y)
F = griddedInterpolant(xx,yy,surf_z,'spline');
% make 3D surface with a some step value
step = 0.01;
[Xq,Yq] = ndgrid(min(surf_x):step:max(surf_x), min(surf_y):step:max(surf_y));
Zq = F(Xq,Yq);
% plot 3D surface
mesh(Xq,Yq,Zq);