Error when building a trend line

1 回表示 (過去 30 日間)
Lev Mihailov
Lev Mihailov 2019 年 7 月 17 日
回答済み: Shashank Sharma 2019 年 7 月 17 日
[cat,nocat]=min(Animals); % cat and dog 1x1200
[dog,nodog=max(Animals); % cat and dog 1x1200
for i=1:length(cat)
pas(i) = polyfit(cat(i),dog(i),1); % error Subscripted assignment dimension mismatch.
fss(i) = polyval(dog(i),cat(i));
end
I'm trying to build a trend line of two values ​​of cats and dogs, but I get an error, help me figure out what's wrong.
Probyval without a loop, gives only the latest values.

採用された回答

Shashank Sharma
Shashank Sharma 2019 年 7 月 17 日
polyfit requires x , y to be vectors. Also, it makes no sense to fit a single value.
It seems to me that your usage of polyval is wrong. Take a look at the docs
https://www.mathworks.com/help/matlab/ref/polyval.html
This is probably what you should be doing,
pas = polyfit(cat,dog,1);
dog_fit = polyval(pas, cat);

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by