Polyfit and Polyval on Reduced Matrices

1 回表示 (過去 30 日間)
AnnieLieseMari
AnnieLieseMari 2022 年 6 月 15 日
コメント済み: Torsten 2022 年 6 月 15 日
Hello!
I'm working with a set of data that needs to have a polyfit and polyval applied to it. However, I initially had to resize the vectors that are being put into the data. Then, I have to plot it.
This is the code that I have. I'm not sure if it's working correctly, as the output numbers for p are nowhere near where I am expecting them to be. It's showing p to be 0.1416, but I'm expecting p to be 50-60...
x and y are both vectors of 2458 x 1 doubles, or I'd attach them here...
figure()
xNew = (linspace(10.5, 16, numel(y)))
p = polyfit(10*log10(xNew),y,1)
f = polyval(p,[10.5 16]);
semilogx(x,y,'o',[10.5 16],f,'-')
Any help is appreciated!

回答 (1 件)

Torsten
Torsten 2022 年 6 月 15 日
You are aware that you fit parameters a and b of the function
f(x) = a + 10*b*log10(x)
to your data vector y ?
Did you try
f = polyval(p,10*log10(xNew));
plot(10*log10(xNew),f)
hold on
plot(10*log10(xNew),y,'-')
  4 件のコメント
AnnieLieseMari
AnnieLieseMari 2022 年 6 月 15 日
So maybe the linspace function is wrong...
What can I do to use only the x values between 10.5 and 16, while extracting the values that correspond from y then?
Yes, the graph is supposed to show the line of best fit to the scatter points that are in x and y.
Torsten
Torsten 2022 年 6 月 15 日
What can I do to use only the x values between 10.5 and 16, while extracting the values that correspond from y then?
You define x to be equispaced in 10.5:16 with as many points as the y-vector. So no need to extract them.
I must admit that I don't understand what you are trying to do.

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by