Plotting Multiple Linear Regressions on the same graph

22 views (last 30 days)
Hello,
I've used the mdl = fitlm(x,y) function to fit a linear regression model to one set of data I have.
I have 10 sets of data.
I'm trying to figure out how to plot these regressions all on the same graph. My data is all in separate matrixes (i.e. set1(x1,y1) data is in a separate matrix from set2(x2,y2) data.
Currently, after runnding mdl=fitlm(x,y) on each set of data, I've tried the code shown below to plot all linear regressions in the same scatter plot graph.
plot(mdl1);hold on;
plot(mdl2);hold on;
etc
The problem with this is it doesn't colour code that data at all, so it is impossible to discern which regression line fits with which set of the data (all the points are blue, and all regression and deviation lines are red). And, the plot function won't seem to let me pick what colour to make the points.
I've tried researching the multiple linear regression plotting in the 'help' section, but it seems to be filled with a lot of technical jargon I can't wrap my head around.
Any suggestions would be welcome, or perhaps an easier way of understanding how to program for a multiple linear regression to plot all this data on one graph.
Thanks Kyle

Answers (1)

Star Strider
Star Strider on 9 Apr 2015
I haven’t experimented with what you want to do (plotting a model structure), but I would explore the possibility of using the get and set functions to change the axis (and line) properties after they are plotted. This can be different in R2014a and earlier, and R2014b and later, depending on what properties you want to change.
  2 Comments
Kyle
Kyle on 10 Apr 2015
The issue of the axis isn't so much the issue, but the line properties are definitely a problem so I will check that out.
Thanks!
Star Strider
Star Strider on 10 Apr 2015
My pleasure!
The line object is a figure property, so using get may be the only way to access the line. See Chart Line Properties for details. (See Graphics Object Properties for all of them, and a general description.)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!