I have a loglog plot of data in MATLAB and I am trying to overlay a linear fit. The linear data fitting tool doesn't work, so I was hoping to simply plot another line of slope -11/3. This line should be linear in a loglog plot, but I am having trouble plotting. Can anyone help? New to MATLAB so any advice would be useful. I have attached a picture of the plot I keep getting. The blue line is the loglog data plot, and the orange line is MATLAB's "linear fit" when using the basic plotting tool.

 채택된 답변

David Goodmanson
David Goodmanson 2017년 7월 11일
편집: Walter Roberson 2017년 7월 12일

0 개 추천

Hello Cameron, If you have a linear fit in the logs,
log(y) = (-11/3)log(x) + A
then exponentiate both sides:
y = x^(-11/3) exp(A)
and with C = exp(A), the fitting line (linear on loglog plot) is
y = C*x.^(-11/3)
where you just have to provide C. C could come from the same theory that gives the -(11/3), in which case you have a fit with no adjustable parameters, nice if it works. Or you could calculate C by using one (x,y) data point, or you could fit A from the first equation by taking the difference between log(y) and (-11/3)*log(x), and averaging that difference over all the values to get A. Then C = exp(A).
If you prefer log base 10, then replace log by log10 and C = exp(A) by C = 10^A everywhere.

댓글 수: 6

Cameron Park
Cameron Park 2017년 7월 11일
Thank you for your response, that definitely helped with creating the line, however I am still having problems plotting them on the same graph. When I plot this line, it erases the last plot of all the data. Any thoughts on how to plot both at once?
David Goodmanson
David Goodmanson 2017년 7월 12일
편집: David Goodmanson 2017년 7월 12일
You could do independent plot commands with 'hold on' active like Walter has mentioned, or you could do
y1 = C*x.^(-11/3);
loglog(x,y,x,y1) [corrected per Walter's comment]
Walter Roberson
Walter Roberson 2017년 7월 12일
Well, loglog(x,y,x,y1)
David Goodmanson
David Goodmanson 2017년 7월 12일
yes.
Cameron Park
Cameron Park 2017년 7월 12일
thank you! I used the hold on method and it worked perfectly! Appreciate the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2017년 7월 11일

댓글:

2017년 7월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by