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)

Matt J
2022 年 2 月 28 日
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.
Matt J
2022 年 2 月 28 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
