Plotting results from "fitnlm" function

12 views (last 30 days)
Anant Sareen
Anant Sareen on 8 Dec 2021
Answered: KSSV on 8 Dec 2021
I am using the fitnlm function to obtain a regression curve for my experiements. I wanted to plot the results of the function on a 3D plot to graphically reperesent the results. I need help as to how that can be done. Please find below the excerpt of my code below. Thanks in advance.
X1 = [0 -5 -5 0 -10 -10 0 5 5 0 10 10 0 -5 5];
X2 = [0 0 5 5 0 10 10 0 -5 -5 0 -10 -10 -5 5];
X = [X1;X2].';
Torque = [15.64 21.15 14.34 13.29 22.83 14.17 9.18 14.63 21.5 24.21 13.04 25.47 28.66 26.68 12.4].
f = @(tb,x) tb(1) + tb(2)*x(:,1) + tb(3)* x(:,2)
opts = statset('Display','iter','TolFun',1e-20);
mdlfit = fitnlm(X, Torque,f, ones(3,1),'Options',opts)
Summary = [Torque predict(mdlfit,X) predict(mdlfit,X)-Torque]

Answers (1)

KSSV
KSSV on 8 Dec 2021
x = Torque ;
y = predict(mdlfit,X) ;
Z = predict(mdlfit,X)-Torque ;
surf(x,y,Z)

Categories

Find more on Time Series in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!