2017-04-23 95 views
0

我有一个矩阵(大约400×400)在0和1之间。这里的数字是3D柱状图的图MATLAB:拟合三维表面的条形图

enter image description here

欲适合条形图的3D表面。有任何想法吗?矩阵的元素(0和1之间的数字)应该给出每个索引处表面的高度。我希望表面只是给我们一般的条形图,而不是每一个点。

回答

1
% init 
x = randn(1000,1); 
y = randn(1000,1); 
nbins = [10 20]; 

% make histogram 
h = histogram2(x,y,nbins) 

enter image description here

% 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) 

enter image description here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% 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); 

enter image description here