fit() from Curve Fitting Toolbox not working even with examples from the documentation

11 ビュー (過去 30 日間)
Wenlin
Wenlin 2022 年 3 月 20 日
編集済み: Wenlin 2022 年 3 月 20 日
I'm trying to use the fit() function from the curve fitting toolbox but it kept giving me an error saying "Data sizes are incompatible."
The script I'm using is directly from the documentation:
load franke
sf = fit([x, y],z,'poly23')
plot(sf,[x,y],z)
I tried it in MATLAB online and it worked perfectly, but not working in MATLAB R2021b. I tried updating it to R2022a which also didn't solve the problem. Not sure if this is a bug or I'm doing something wrong.

採用された回答

Matt J
Matt J 2022 年 3 月 20 日
Run the code inside a function,
>> myfunction
function myfunction
load franke
sf = fit([x, y],z,'poly23')
plot(sf,[x,y],z)
end
  3 件のコメント
Matt J
Matt J 2022 年 3 月 20 日
編集済み: Matt J 2022 年 3 月 20 日
Where were you running it before? In any case, there was clearly something in your environment interfering. Maybe a variable named 'fit'? Try clearing your workspace and redoing whatever it is you did originally.
Wenlin
Wenlin 2022 年 3 月 20 日
編集済み: Wenlin 2022 年 3 月 20 日
I was running it just as a script before. I tried clearing the workspace or restarting from a blank instance a few times before but that didn't solve it either. It seems to be working fine now but still not sure what have caused it.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 3 月 20 日
What does this show
size([x, y])
size(z)
Don't use a semicolon and tell us what it says the sizes are in the command window.

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by