fitlm and exponential model help
4 views (last 30 days)
Show older comments
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?
Accepted Answer
Star Strider
on 5 Oct 2022
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)
[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')
.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!