簡體   English   中英

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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM