How do I extract the exponent from a semilogy plot?

If I use semilogy to plot some data such that the plot appears as a straight line, how can I extract the exponent of this line? Can I use polyfit to get this or is there a different way?

 Respuesta aceptada

Stephan
Stephan el 26 de Feb. de 2019
Editada: Stephan el 26 de Feb. de 2019

0 votos

Hi,
i think you should use lsqcurvefit (requires Optimization Toolbox) or fit (requires Curve Fitting Toolbox) - depending on the toolboxes you have access to. I would expect an exponential function if there is a straight line in the semilogy plot. Due to this polyfit is not the correct choice. I recommend to work through this examples:
lsqcurvefit:
fit:
In case of lsqcurvefit the resulting elements of solutiuon x contain the needed exponent. In case of fit you get the values with the coeffvalues function.Therefore see also Fit Postprocessing.
Best regards
Stephan

4 comentarios

Hi, thanks for your help, I'm having a go with fit but struggling to get it to work. I have a very small data set , with
x = [2.3561 2.4831 2.6233];
y = [0.2452 1.4632 1.6916];
which I'm trying to fit to the curve a*exp(-b*x). The fit isn't very good but I need to look into how good it is so I need to fit something of this form to it. I tried to use
expfit = fittype('a*exp(-b*x)','dependent',{'y'},'independent',{'x'},'coefficients',{'a','b'})
fitEa = fit(x',y',expfit)
but this gave me the error
Function 'subsindex' is not defined for values of class 'fittype'. How can I do this correctly?
Stephan
Stephan el 26 de Feb. de 2019
Editada: Stephan el 26 de Feb. de 2019
I dont get an error with your fittype - which Matlab Release do you use?
x = [2.3561 2.4831 2.6233];
y = [0.2452 1.4632 1.6916];
expfit = fittype('a*exp(-b*x)','dependent',{'y'},'independent',{'x'},...
'coefficients',{'a','b'})
f = fit(x',y',expfit);
fvals = f(x);
format long
coeffs = coeffvalues(f)
names = coeffnames(f)
format short
subplot(2,1,1)
plot(f,x,y)
legend('Location','southeast')
subplot(2,1,2)
semilogy(x,fvals)
ylim([0 2])
No worries, I sorted it - I had another variable stored as fit from a different part of the code! Thanks for your help!
Stephan
Stephan el 26 de Feb. de 2019
No problem - if this was useful for you please accept my answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Feb. de 2019

Comentada:

el 26 de Feb. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by