How to find the intersection of a fitting line with a logarithmic y-axis?

조회 수: 4 (최근 30일)
Lu Da Silva
Lu Da Silva 2021년 10월 2일
답변: Kevin Holly 2021년 10월 2일
I have a vector A = [10 40 60 80]
and a vecor B = [5 6 7 8]
I need to create a plot where the x-axis is B and the y-axis is A in the logarithmic scale. Then I need to find the intersection of the fitting line of the scatter with the y-axis.
I used semilogy(B,A) but that only gives me the line and I need to find the intersection.

답변 (1개)

Kevin Holly
Kevin Holly 2021년 10월 2일
A= [10 40 60 80];
B = [5 6 7 8];
scatter(B,A,20,'filled')
set(gca,'YScale','log')
% Polyfit
p = polyfit(B,A,2);% 2nd order
f1 = polyval(p,B);
hold on
plot(B,f1,'r--') % poly fit as red dashed line
semilogy(B,A,'g') %log fit as green line
myfit = fittype('a + b*log(x)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a','b'});
[model stats] = fit(B',A',myfit)
Warning: Start point not provided, choosing random start point.
model =
General model: model(x) = a + b*log(x) Coefficients (with 95% confidence bounds): a = -226.1 (-265.5, -186.7) b = 147.4 (126.2, 168.5)
stats = struct with fields:
sse: 5.9358 rsquare: 0.9978 dfe: 2 adjrsquare: 0.9967 rmse: 1.7228
plot(B,model(B),'b') % log fit as blue line
I am not quite sure how to calculate the intersection, but found this:

카테고리

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