2

I am new to MATLAB and am having difficulty plotting multiple graphs. Here are my vectors to graph:

S = [1.2421
     2.3348
     0.1326
     2.3470
     6.7389
     3.7089
     11.8534
     -1.8708
     ...]

Y = [1.1718
     1.8824
     0.3428
     2.1057
     1.6477
     2.3624
     2.1212
    -0.7971
    ...]

w = [0.1753
     0.3277]

S is my training data and Y is my output vector. Then I add a column vector to my training data:

O = ones(length(S), 1)
X = [S 0]

w = inv(X'*X)*X'*Y

So I am trying to plot X, Y and w on the same graph. I plot w first, hold, X and this is where I get lost. Basically they are not on the same scale because the size of x is much less than X (X and Y are both vectors of size 100 and w is of size 2).

plot(w)

In MATLAB: result of plot(w)

Then I do:

hold
plot(X)

In MATLAB: result of hold, plot(X)

Now the w that I plotted is so small compared to the plot of X. How would I make them the same scale? Also maybe making them a different color?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gprime
  • 2,283
  • 7
  • 38
  • 50
  • Do you need to have them in the same plot? The x- and y-scales of your two plots are very different. Maybe its better to plot them side-by-side using [subplot](http://www.mathworks.de/help/techdoc/ref/subplot.html). – Dario Seidl Sep 24 '11 at 20:44
  • possible duplicate of [Plotting 4 curves in a single plot, with 3 y-axes](http://stackoverflow.com/questions/1719048/plotting-4-curves-in-a-single-plot-with-3-y-axes) – Amro Sep 24 '11 at 21:11

2 Answers2

4

plotyy will create the figure you are looking for. See the examples in the link for further plot customization.

zellus
  • 9,617
  • 5
  • 39
  • 56
0

I'd just comment, but I don't have enough reputation... If you are not aiming to present the data, but just be able to visualize it, you can rescale your datasets and avoid the not-so-easy-to-work-with plotyy (although it is the best answer):

W = W/max(W);
X = X/max(X);
plot(W)
hold on
plot(X)

For additional formating of the plots, see mathworks polt. There you can change color, linewidth and whatnot.

Puff
  • 503
  • 1
  • 4
  • 14