【答案】应助回帖
★ ★ 感谢参与,应助指数 +1 dbb627:编辑内容 2011-12-10 19:54 dbb627(金币+2): 感谢应助 2011-12-10 20:01:46 rulin11(金币+2): 谢谢,你的回复,已经解决O(∩_∩)O~ 2011-12-12 14:45:37
下面的程度是基于1楼的思路写的,LZ可以按自己的数据生成具体的data.
基本的想法就是将对应于第个点的不同的Z值进行平均(也可以选用不同的方法得到不同的平均值。),通过拟合平均后的Z值,得到面,并将其画出。
我这里每个点会有5个不同的Z值,我看你的程序这个数是不一定的,没关系,程序中是可以自己判断,生成均值的。
看看有什么要求。具体还有其它的问题,可以再问。CODE: clear all
clc
% generate the numbers by :
% [url]http://muchong.com/bbs/viewthread.php?tid=3918964&fpage=1[/url]
n1=100;
n2=n1*10;
x=rand(n1,1);
y=rand(n1,1);
z=rand(n2,1);
x_new=repmat(x,[n2/n1,1]);
y_new=repmat(y,[n2/n1,1]);
% transform the data
data=[x_new';y_new';z']';
% calculate the mean value of each point.
for i=1:n1
ind=[data(:,1)==x(i)&data(:,2)==y(i)];
z_temp=data(ind,:);
z_mean(i)=mean(z_temp(:,3));
end
% output the data.
x_temp=[min(x):(max(x)-min(x))/n1:max(x)];
y_temp=[min(y):(max(y)-min(y))/n1:max(y)];
[X,Y]=meshgrid(x_temp,y_temp);
Z = griddata(x,y,z_mean,X,Y);
mesh(X,Y,Z)
hold on
plot3(x,y,z_mean,'o')
% if u feel the original point is too chaos, u can ctrl+r the following
% codes
plot3(x_new,y_new,z,'r.')
hold off
% typed by : mm
% typed on : 19:28 2011-12-10
[ Last edited by dbb627 on 2011-12-10 at 19:54 ]