2 ethan  wong Ethan__Wong 于 2014.08.21 09:41 提问

matlab拟合出错,求大神

直接上代码
A=xlsread('E:\matlabspace\yuanzhu','sheet2','a1261:c2521');
x=A(:,1);
y=A(:,2);
z=A(:,3);
data=[x(:),y(:),z(:)];

f=@(p,data)(data(:,1)-p(1)).^2+(data(:,2)-p(2)).^2+(data(:,3)-p(3)).^2-p(4)^2;
p=nlinfit(data,zeros(size(data,1),1),f,[0 0 0 1]')%拟合的参数

plot3(data(:,1),data(:,2),data(:,3),'o')
[X,Y,Z]=meshgrid(linspace(-14,14));
V=(X-p(1)).^2+(Y-p(2)).^2+(Z-p(3)).^2-p(4)^2;
isosurface(X,Y,Z,V,0);
alpha .5;camlight;axis equal;grid on;view(3);
title(sprintf('(x-%f)^2+(y-%f)^2+(z-%f)^2=%f',p(1),p(2),p(3),p(4)^2))

错误提示:
??? Error using ==> nlinfit at 120
Error evaluating model function '@(p,data)data(:,1)^2.*p(1)+data(:,2)^2.*p(2)+data(:,3)^2.*p(3)-1'.

Error in ==> Untitled at 10
p=nlinfit(data,zeros(size(data,1),1),f,[1 1 1])%拟合的参数

Caused by:
Error using ==> mpower
Inputs must be a scalar and a square matrix.

Csdn user default icon
上传中...
上传图片
插入图片