Calculating Error and intercept on a log plot

6 visualizaciones (últimos 30 días)
P_L
P_L el 17 de Abr. de 2019
Editada: P_L el 18 de Abr. de 2019
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');

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 17 de Abr. de 2019
Editada: KALYAN ACHARJYA el 17 de Abr. de 2019
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 comentario
P_L
P_L el 18 de Abr. de 2019
Editada: P_L el 18 de Abr. de 2019
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')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by