Calculating Error and intercept on a log plot

조회 수: 4 (최근 30일)
P_L
P_L 2019년 4월 17일
편집: P_L 2019년 4월 18일
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에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by