You are Here: Home >< Maths

Matlab watch

1. hi, im having some troubles with matlab.

lets say there's two lines that needed to be plotted.

one of the lines we will call the maximum, which would be

x = [1 2 3 4 5]
y = [1 2 3 4 5]
, the other line we will call the minimum, which would be

x = [1 2 3 4 5]
y = [1 4 6 8 10]

I need to find a third line which is the average, how do i program matlab to do this, and put all the 3 lines on the same graph?

2. (Original post by Jukukiwaiyi)
hi, im having some troubles with matlab.

lets say there's two lines that needed to be plotted.

one of the lines we will call the maximum, which would be

x = [1 2 3 4 5]
y = [1 2 3 4 5]
, the other line we will call the minimum, which would be

x = [1 2 3 4 5]
y = [1 4 6 8 10]

I need to find a third line which is the average, how do i program matlab to do this, and put all the 3 lines on the same graph?

I THINK I see what you're trying to do so I'll give it a go. Firstly, you're going to want to give these variables different names really so as to not confuse matlab. Perhaps something like

x=[1 2 3 4 5]
ymax=[1 2 3 4 5]
ymin = [1 4 6 8 10]

and by average, I suppose you just mean the average of the two y vectors? In which case you could do something like
yavg=(ymin+ymax)./2 which will give you the average of ymin and ymax. To plot them, just use plot(x,ymax); hold on; plot(x,ymin); hold on; plot(x,yavg). And this will give you all three on the same graph. Is this what you wanted?
3. what you said looks right, necro.
4. Urgh, ive got to learn this crap for an exam next week
5. (Original post by Nick Longjohnson)
Urgh, ive got to learn this crap for an exam next week
if you're doing engineering, i doubt it would be this difficult!
6. okeis thanks guys
7. (Original post by Nick Longjohnson)
Urgh, ive got to learn this crap for an exam next week
i have to say your sig and profile are awesome

and i HATE matlab, it is BS...even if it does make my life easier lol
8. (Original post by Necro Defain)
I THINK I see what you're trying to do so I'll give it a go. Firstly, you're going to want to give these variables different names really so as to not confuse matlab. Perhaps something like

x=[1 2 3 4 5]
ymax=[1 2 3 4 5]
ymin = [1 4 6 8 10]

and by average, I suppose you just mean the average of the two y vectors? In which case you could do something like
yavg=(ymin+ymax)./2 which will give you the average of ymin and ymax. To plot them, just use plot(x,ymax); hold on; plot(x,ymin); hold on; plot(x,yavg). And this will give you all three on the same graph. Is this what you wanted?
soww wont lemme give you rep, i already given you rep 2 days a go
9. (Original post by dichr0ic)
if you're doing engineering, i doubt it would be this difficult!
Its a heck of a lot worse.

"write a program to calculate prime numbers until the user stops the program/up to an upper limit set by the user" (((

wait theres more "Apply a symmetric low-pass filter to create a filtered signal (z) from the mean value of itself and its neighbours..." This is on an array x of integers 0-300, and an array y (300 random numbers of 0-1). God im screwed

Related university courses

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: February 14, 2010
Today on TSR

Top unis in Clearing

Tons of places at all these high-ranking unis

Poll
Useful resources

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

How to use LaTex

Writing equations the easy way

Study habits of A* students

Top tips from students who have already aced their exams

Chat with other maths applicants