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?

2
  • 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. Commented Sep 24, 2011 at 20:44
  • possible duplicate of Plotting 4 curves in a single plot, with 3 y-axes Commented Sep 24, 2011 at 21:11

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.