Polyfit for loop not recording results

4 ビュー (過去 30 日間)
Daniel Gaggini
Daniel Gaggini 2022 年 4 月 26 日
回答済み: Walter Roberson 2022 年 4 月 26 日
I am trying to create a forloop that stores values from a polyfit operation, I am getting the error message:
"Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
This is what I have
x = x_coordinates
y = y_coordinates
Counter = 1:15;
for i = Counter;
Fit_Best(i)=polyfit(x,y,i);
end
Does anybody know where my mistake is?

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 4 月 26 日
polyfit returns a vector of coefficients which has one more entries as the given degree. degree 2 has 3 entries and so on. But you are trying to store the results in a scalar each time.
Look at cell arrays.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by