フィルターのクリア

Polyfit: How to use?

2 ビュー (過去 30 日間)
Sarah Kirchler
Sarah Kirchler 2020 年 7 月 10 日
回答済み: Cris LaPierre 2020 年 7 月 10 日
Dear MatLab community!
I'd like to lay a line of best fit in my scatterplot.
I did the following:
figure;scatter(stimsAt10Hz_outdet(:,1),AQS(:,2), 40, [0.2 0.35 1], 'filled')
grid on
xlabel('Magnitude(z)')
ylabel('ASQ-Score')
title('Corr(Contour,ASQ)')
polyfit(stimsAt10Hz_outdet, AQS,1)
But nothing happens.
Do anyone find the error? I am not sure if I used polyfit in the right way..
I would be really thankful to hear something from you.
Thank you in advance!

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 7 月 10 日
I recommend using the examples in the documentation to guide you.
Here, you must use the exact same x and y values that you used in your plot command: stimsAt10Hz_outdet(:,1),AQS(:,2). You are passing in more. Polyfit does not know how to handle the extra data.
Polyfit also only returns the coefficients. Use polyval to calculate your fit's y values from a provided x vector. Then use hold on and plot commands to add your fit lines to your figure. See this example.

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by