# fitlm and exponential model help

3 views (last 30 days)
Dharmesh Joshi on 4 Oct 2022
Answered: Star Strider on 5 Oct 2022
Hi
I have a set of data, which is voltage from a sensor aganist temperture.
As temperture increase the voltage output from the sensor will drop, even though the sensing enviroment in the same.
Therefore i need to be able to calulate the correction factor so the output is very close to when sensor is expose to 20 degrees.
I am using fitlm, but when i use exponential i am getting errors, which is not then when i use Quadratic
This is what i am using
no2Model = fitlm(iot_temperature, voltage_differnce_no2, "exponential");
Is this the correct command to use?
Mathieu NOE on 5 Oct 2022
hello
can you share the data + code ?

Star Strider on 5 Oct 2022
The "exponential" option for modelspec does not appear to exist.
The fitnlm function is likely more appropriate. That is more likely to produce the result you want.
Example —
t = linspace(0, 10, 25);
y = 3*exp(-0.25*t) + 0.5*randn(size(t)) + 1;
fcn = @(b,x) b(1).*exp(b(2).*x) + b(3);
B0 = randn(3,1);
mdl = fitnlm(t,y,fcn,B0)
mdl =
Nonlinear regression model: y ~ b1*exp(b2*x) + b3 Estimated Coefficients: Estimate SE tStat pValue ________ _______ _______ __________ b1 2.7569 0.44251 6.2301 2.8587e-06 b2 -0.2526 0.12197 -2.0711 0.050281 b3 1.0658 0.48102 2.2157 0.037369 Number of observations: 25, Error degrees of freedom: 22 Root Mean Squared Error: 0.519 R-Squared: 0.696, Adjusted R-Squared 0.669 F-statistic vs. constant model: 25.2, p-value = 2.01e-06
[yfit,yci] = predict(mdl,t(:));
figure
hp{1} = plot(t, y, '.', 'DisplayName','Data');
hold on
hp{2} = plot(t, yfit, '-r', 'DisplayName','Model Fit');
hp{3} = plot(t, yci, ':r', 'DisplayName','±95% CI');
hold off
grid
xlabel('t')
ylabel('y')
legend([hp{1},hp{2},hp{3}(1)], 'Location','best')
.

### Categories

Find more on Linear Predictive Coding in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by