Clear Filters
Clear Filters

How to have linear regression data appear on figure as text?

1 view (last 30 days)
Hello,
I'd like to have some linear regression data appear on a figure.
Currently, the code appear as:
for x = B(1:19,5)
for y = B(1:19,12);
figure(1);
subplot(3,1,1);
scatter(x,y); grid on;
hold on
lsline
mdl = fitlm(x,y);
str1 = 'r^2 = 0.800'; %This is found by looking at the output in the command window and manually entering the value back in
text(20,250,str1); %Manually entered text location, but would be happy with it appearing elsewhere
end
end
I would like both the r^2 value and the equation of the line to appear on the figure.
Any guidance or suggestions are greatly appreciated.
Cheers

Answers (0)

Community Treasure Hunt

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

Start Hunting!