Calculating Error and intercept on a log plot
6 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
this is the code/ data I have. Please note I have already taken the logs so that the data is scaled appropriately.
Log_N = [1.09861228866811,1.09861228866811,1.79175946922806,2.56494935746154,3.61091791264422,4.23410650459726,4.65396035015752];
Log_R = [-2.50000000000000,-2,-1.50000000000000,-1,-0.500000000000000,0,0.500000000000000];
plot(Log_R,Log_N,'o')
hold on
title('Correlation Dimension')
xlabel('Log R')
ylabel('Log Nd')
hold on
[P, S,] = polyfit(Log_R,Log_N,1);
% Evaluate the fitted polynomial p and plot:
f = polyval(P,Log_R);
plot(Log_R,Log_N,'o',Log_R,f,'-')
legend('data','linear fit')
I have created my line of best fit using polyfit and polyval. All I am wanting to do is fit a straight line to my data and would like to know my gradient of the line/ slope and the associated error.
Any advice would be much appreciated.
I tried using 'fit'
[curve, ~] = fit(Log_R, Log_N,'poly1');
but the errors I got were:
>> correlation_attempt_2
Error using fit>iFit (line 127)
X must be a matrix with one or two columns.
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in correlation_attempt_2 (line 72)
[curve, ~] = fit(Log_R, Log_N,'poly1');
0 件のコメント
採用された回答
KALYAN ACHARJYA
2019 年 4 月 17 日
編集済み: KALYAN ACHARJYA
2019 年 4 月 17 日
ERROR
Error using fit>iFit (line 127)
X must be a matrix with one or two columns.
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in ans_matlab_april19 (line 17)
Threfore I did transpose
[curve, ~]=fit(Log_R', Log_N','poly1');
figure, plot(curve,Log_R,Log_N)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!