Curve fitting(toolbox) 3d plot is different when using surf
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I use the curve fitting toolbox and is was what I get:


However, when I try to use 'surf' to plot the 3d plot above it turns out:
[Xtest1, Xtest2] = meshgrid(xtest1, xtest2);
p00 = -0.4888 ;
p10 = 0.04507 ;
p01 = 0.1304 ;
p20 = 0.005239 ;
p11 = -0.01134 ;
p02 = -0.009979 ;
p30 = 0.0005176 ;
p21 = 0.0002514 ;
p12 = 0.0005639 ;
p03 = 0.0002402 ;
z = p00 + p10.*Xtest1 + p01.*Xtest2 + p20.*Xtest1.^2 + p11.*Xtest1.*Xtest2 + p02.*Xtest1.^2 + p30.*Xtest1.^3 + p21.*Xtest1.^2.*Xtest2 + p12.*Xtest1.*Xtest2.^2 + p03.*Xtest2.^3;
surf(Xtest1,Xtest2,z)

The plot using 'surf' is not as same as the plot from curve fitting toolbox at all. Apparently the maximum in curve fitting toolbox and surf plot are different. The data xtest1 and xtest2 are same for both curve fitting toolbox and meshgrid, I wonder what is wrong with the code above?
채택된 답변
It looks like you have transcribed the fitted coefficients manually from the display, and only to 4 decimal places. (It also looks like you might have interchanged xtest1 with xtest2.)
The more reliable thing to do would be to save the fit tot the Matlab workspace, and then use the fit object to Evaluate the Surface Fit.

댓글 수: 11
Thanks, I try the 'save to workspace' but the plot is still different, is there any reason why the 'surf' plot is different than the toolbox plot?
[Xtest1, Xtest2] = meshgrid(xtest1, xtest2);
p00 = -0.488757962540892 ;
p10 = 0.045069636734440 ;
p01 = 0.130432889884869 ;
p20 = 0.005238941763348 ;
p11 = -0.011336736979518 ;
p02 = -0.009978572315984 ;
p30 = 5.176228350092313e-04 ;
p21 = 2.514499348728134e-04 ;
p12 = 5.638521763257720e-04 ;
p03 = 2.401613755575195e-04 ;
z = p00 + p10.*Xtest1 + p01.*Xtest2 + p20.*Xtest1.^2 + p11.*Xtest1.*Xtest2 + p02.*Xtest1.^2 + p30.*Xtest1.^3 + p21.*Xtest1.^2.*Xtest2 + p12.*Xtest1.*Xtest2.^2 + p03.*Xtest2.^3;
surf(Xtest1,Xtest2,z)

If you attach the fit object that you exported in a .mat file, we can more easily examine why differerences may be occurring.
Hello, these are my fit .mat files
The difference in the appearance of the two plots is simply that the cftool is overlaying the input zzz data onto the final fit. Here is what the fit, without the data, looks like.
load fittedmodel
plot(fittedmodel); view(20,30)

If you wanted to reproduce the plot with the overlaid data, you would do,
plot(fittedmodel,[xtest1(:), xtest2(:)],zzz(:))
Thanks, but I still do not understand why I cannot create the same plot with 'surf', I need to use that function so I need to try to create the plot with 'surf'. Also, an error occurs with the code above:
plot(fittedmodel,[xtest1(:), xtest2(:)],zzz(:))
error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Thanks, but I still do not understand why I cannot create the same plot with 'surf', I need to use that function so I need to try to create the plot with 'surf'.
No, you don't need surf(). All fit post plotting can be done with the fittedmodel object.
Also, an error occurs with the code above:
Again, hard to do anything if you don't attach the data. We need the input data xtest1, xtest2, zzz that was used to generate the fit.
Sorry, but I mean I need to use the function from curve fitting toolbox 'f(x,y) = p00 + p10*x + p01*y + p20*x^2 + ...' in other project, so I need to make sure the 'surf' plot is correct, however it seems incorrect when using 'surf'.
Here are the files:
Here is a conventionally generated surf plot, together with that from the cftool app. As you can see, there is close agreement between them, and with the plot we generated earlier using the fittedmodel object.
load fittedmodel
coeffs=num2cell( coeffvalues(fittedmodel) );
[p00 p10 p01 p20 p11 p02 p30 p21 p12 p03]=deal(coeffs{:});
[x,y]=meshgrid(xtest1,xtest2);
z= p00 + p10.*x + p01.*y + p20.*x.^2 + p11.*x.*y + p02.*y.^2 + p30.*x.^3 + p21.*x.^2.*y + p12.*x.*y.^2 + p03.*y.^3;
surf(x,y,z,'EdgeColor','none'); view(20,30)
hold on
scatter3(x(:),y(:),zzz(:),'filled','SizeData',5,'MarkerFaceColor','k')
hold off


Thanks, I think the problem is probably due to 'meshgrid', but anyway I can create the plot by using 'surf' now.
No, I've revised my code above to use meshgrid(). There is still very close agreement.
Yeah, the problem is I use the 'meshgrid' incorrectly.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
