2

I'm plotting a linear regression using the MATLAB function plotregression in this way:

hand = plotregression(x, y, 'Regression')

However, I'd like to get rid of the y = T line in the plot, and also use a different marker, such as *. How can I do this? I've already tried set(hand, ..,) but it didn't work.

Eitan T
  • 32,660
  • 14
  • 72
  • 109
Paula
  • 21
  • 1
  • 4
  • 1
    I'm not sure that it can be done with `plotregression`, but as a workaround you could use [`polyfit`](http://www.mathworks.com/help/matlab/ref/polyfit.html) in combination with [`polyval`](http://www.mathworks.com/help/matlab/ref/polyval.html), as suggeted [here](http://stackoverflow.com/q/11209974/1336150#11210035). – Eitan T Sep 12 '13 at 17:13
  • 2
    Yes, polyfit and polyval worked perfectly for my purpose. Thank you! – Paula Sep 12 '13 at 17:35

1 Answers1

0

The plotregression function returns the handle to a figure. This figure has 3 children: legend, axis, and a uicontrol. For a simple call the uicontrol is not visible. The axis has also has 3 children: data, fit, y = T. To get what you want we need to delete the third child of the second child and change the marker of the of the first child of the second child. We then need to regenerate the legend since it does not dynamically update.

x = 1:10;
y = randn(1, 10);
hand = plotregression(x, y, 'Regression');
h = get(hand, 'Children');
hh = get(h(2), 'Children');
delete(hh(3))
set(hh(1), 'Marker', '*')
legend('Data', 'Fit', 'Location', 'NorthWest');
StrongBad
  • 869
  • 6
  • 16