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!