Calculating Error and intercept on a log plot

2 次查看(过去 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');

采纳的回答

KALYAN ACHARJYA
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)
66.png
  1 个评论
P_L
P_L 2019-4-18
编辑:P_L 2019-4-18
Many Many thanks!! solved my problem!
I am trying to amend my data points so that appear larger- the 'MarkerSize' command isn't working - is there another way I need to do it?
This is what I am trying:
figure, plot(curve,Log_R,Log_N,'o','MarkerSize',12, 'MarkerFaceColor', 'b')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile 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!

Translated by