Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plotting max and min

Subject: Plotting max and min

From: Julian

Date: 18 Feb, 2010 18:50:05

Message: 1 of 7

Hello all,
  I must be going through a long day, because I am stumped on something that I think should be very minute. However, I am trying to plot multiple plots in my graph with no success. This is a snippet of my code. More or less this is the end of my code.

data1 = var1-var2
lower = min(data1);
upper = max(data1);
avg = mean(data1);

plot(data1,'r*')
hold on
plot(upper,'m.')
plot(lower,'y.')
plot(avg,'g.')

Now, I plot the first point, plot(data1,'r*') no problem. And I do realize I can just go to Data statistics to find out the max, min, etc. But I want this code to be as automatic as I can. With that said, I have to say, I seem to not seem to know my basics today. Any help would be appreciated.

Subject: Plotting max and min

From: Sadik

Date: 18 Feb, 2010 19:04:22

Message: 2 of 7

How about

plot(data1,'r*')
hold on
plot(upper*ones(size(data1)),'m.')
plot(lower*ones(size(data1)),'y.')
plot(avg*ones(size(data1)),'g.')


"Julian " <sadsd@aol.com> wrote in message <hlk24t$3g3$1@fred.mathworks.com>...
> Hello all,
> I must be going through a long day, because I am stumped on something that I think should be very minute. However, I am trying to plot multiple plots in my graph with no success. This is a snippet of my code. More or less this is the end of my code.
>
> data1 = var1-var2
> lower = min(data1);
> upper = max(data1);
> avg = mean(data1);
>
> plot(data1,'r*')
> hold on
> plot(upper,'m.')
> plot(lower,'y.')
> plot(avg,'g.')
>
> Now, I plot the first point, plot(data1,'r*') no problem. And I do realize I can just go to Data statistics to find out the max, min, etc. But I want this code to be as automatic as I can. With that said, I have to say, I seem to not seem to know my basics today. Any help would be appreciated.

Subject: Plotting max and min

From: TideMan

Date: 18 Feb, 2010 19:09:45

Message: 3 of 7

On Feb 19, 7:50 am, "Julian " <sa...@aol.com> wrote:
> Hello all,
>   I must be going through a long day, because I am stumped on something that I think should be very minute.  However, I am trying to plot multiple plots in my graph with no success.  This is a snippet of my code.  More or less this is the end of my code.
>
> data1 = var1-var2
> lower = min(data1);
> upper = max(data1);
> avg = mean(data1);
>
> plot(data1,'r*')
> hold on
> plot(upper,'m.')
> plot(lower,'y.')
> plot(avg,'g.')
>
> Now, I plot the first point, plot(data1,'r*') no problem.  And I do realize I can just go to Data statistics to find out the max, min, etc.  But I want this code to be as automatic as I can.  With that said, I have to say, I seem to not seem to know my basics today.  Any help would be appreciated.

What is the abscissa?
You need to define one.
Even x=[1:length(data1)]'; would do.
Then:
> plot(x,data1,'r*')
> hold on
> plot(x,upper*ones(length(x),1),'m.')
or
plot([x(1) x(end)],[upper upper],'m-')

etc

Subject: Plotting max and min

From: Julian

Date: 18 Feb, 2010 19:27:02

Message: 4 of 7

Sadik and TideMan,
  Thank you both for your inputs. Both solutions provided were correct and worked very well.

TideMan,
  That was very crafty to think of defining an abscissa first. I honestly didn't think of doing that because my script basically takes from a file, searches through it and plots a truth from two user defined points. I would assume, the starting point that the user defines would be used as a started to plot. I think I would've thought of Sadiks method before I thought of yours. I appreciate your method. Gives me a great direction to think of.

Sadik, can't leave you out. Thank you for input as well.

Thanks to you both for your swift responses.

TideMan <mulgor@gmail.com> wrote in message <367f375f-6705-41e8-a9e5-1a0d80ff250e@b7g2000pro.googlegroups.com>...
> On Feb 19, 7:50 am, "Julian " <sa...@aol.com> wrote:
> > Hello all,
> >   I must be going through a long day, because I am stumped on something that I think should be very minute.  However, I am trying to plot multiple plots in my graph with no success.  This is a snippet of my code.  More or less this is the end of my code.
> >
> > data1 = var1-var2
> > lower = min(data1);
> > upper = max(data1);
> > avg = mean(data1);
> >
> > plot(data1,'r*')
> > hold on
> > plot(upper,'m.')
> > plot(lower,'y.')
> > plot(avg,'g.')
> >
> > Now, I plot the first point, plot(data1,'r*') no problem.  And I do realize I can just go to Data statistics to find out the max, min, etc.  But I want this code to be as automatic as I can.  With that said, I have to say, I seem to not seem to know my basics today.  Any help would be appreciated.
>
> What is the abscissa?
> You need to define one.
> Even x=[1:length(data1)]'; would do.
> Then:
> > plot(x,data1,'r*')
> > hold on
> > plot(x,upper*ones(length(x),1),'m.')
> or
> plot([x(1) x(end)],[upper upper],'m-')
>
> etc

Subject: Plotting max and min

From: Julian

Date: 18 Feb, 2010 19:27:02

Message: 5 of 7

Sadik and TideMan,
  Thank you both for your inputs. Both solutions provided were correct and worked very well.

TideMan,
  That was very crafty to think of defining an abscissa first. I honestly didn't think of doing that because my script basically takes from a file, searches through it and plots a truth from two user defined points. I would assume, the starting point that the user defines would be used as a started to plot. I think I would've thought of Sadiks method before I thought of yours. I appreciate your method. Gives me a great direction to think of.

Sadik, can't leave you out. Thank you for input as well.

Thanks to you both for your swift responses.

TideMan <mulgor@gmail.com> wrote in message <367f375f-6705-41e8-a9e5-1a0d80ff250e@b7g2000pro.googlegroups.com>...
> On Feb 19, 7:50 am, "Julian " <sa...@aol.com> wrote:
> > Hello all,
> >   I must be going through a long day, because I am stumped on something that I think should be very minute.  However, I am trying to plot multiple plots in my graph with no success.  This is a snippet of my code.  More or less this is the end of my code.
> >
> > data1 = var1-var2
> > lower = min(data1);
> > upper = max(data1);
> > avg = mean(data1);
> >
> > plot(data1,'r*')
> > hold on
> > plot(upper,'m.')
> > plot(lower,'y.')
> > plot(avg,'g.')
> >
> > Now, I plot the first point, plot(data1,'r*') no problem.  And I do realize I can just go to Data statistics to find out the max, min, etc.  But I want this code to be as automatic as I can.  With that said, I have to say, I seem to not seem to know my basics today.  Any help would be appreciated.
>
> What is the abscissa?
> You need to define one.
> Even x=[1:length(data1)]'; would do.
> Then:
> > plot(x,data1,'r*')
> > hold on
> > plot(x,upper*ones(length(x),1),'m.')
> or
> plot([x(1) x(end)],[upper upper],'m-')
>
> etc

Subject: Plotting max and min

From: dpb

Date: 18 Feb, 2010 19:40:10

Message: 6 of 7

Julian wrote:
> Hello all,
> I must be going through a long day, because I am stumped on something
> that I think should be very minute. However, I am trying to plot
> multiple plots in my graph with no success. This is a snippet of my
> code. More or less this is the end of my code.
>
> data1 = var1-var2
> lower = min(data1);
> upper = max(data1);
> avg = mean(data1);
>
> plot(data1,'r*')
> hold on
> plot(upper,'m.')
> plot(lower,'y.')
> plot(avg,'g.')
>
> Now, I plot the first point, plot(data1,'r*') no problem. And I do
> realize I can just go to Data statistics to find out the max, min, etc.
> But I want this code to be as automatic as I can. With that said, I
> have to say, I seem to not seem to know my basics today. Any help would
> be appreciated.

Well, it's confusing when you say plot the first "point" -- one would
presume that should be a vector of points (plural) in order to have a
line.

If not, there's nothing meaningful for min,max,mean to operate on as
they're all going to be identical.

If is a vector (plotted as points instead of a line), then I suppose
you're also looking for line() to draw the statistics. If not, you need
a loop or some other way to create the first vector initially.

--

Subject: Plotting max and min

From: Julian

Date: 18 Feb, 2010 20:01:19

Message: 7 of 7

You're right. My terminology was wrong. You are right in assuming that what I actually meant by point was to say that it is a vector of points. I needed both the line and the numerical equivalent.

Also, for my own benefit for processing data, once the maximum (line) is found (which it is thanks to tideman and sadik) I need to take the absolute value of data1 and calculate the percentage above the criteria (percentage above the max) in which, if any, points may occur. Guess that's another tangent i'm on :). Makes sense now I hope?

dpb <none@non.net> wrote in message <hlk55l$839$1@news.eternal-september.org>...
> Julian wrote:
> > Hello all,
> > I must be going through a long day, because I am stumped on something
> > that I think should be very minute. However, I am trying to plot
> > multiple plots in my graph with no success. This is a snippet of my
> > code. More or less this is the end of my code.
> >
> > data1 = var1-var2
> > lower = min(data1);
> > upper = max(data1);
> > avg = mean(data1);
> >
> > plot(data1,'r*')
> > hold on
> > plot(upper,'m.')
> > plot(lower,'y.')
> > plot(avg,'g.')
> >
> > Now, I plot the first point, plot(data1,'r*') no problem. And I do
> > realize I can just go to Data statistics to find out the max, min, etc.
> > But I want this code to be as automatic as I can. With that said, I
> > have to say, I seem to not seem to know my basics today. Any help would
> > be appreciated.
>
> Well, it's confusing when you say plot the first "point" -- one would
> presume that should be a vector of points (plural) in order to have a
> line.
>
> If not, there's nothing meaningful for min,max,mean to operate on as
> they're all going to be identical.
>
> If is a vector (plotted as points instead of a line), then I suppose
> you're also looking for line() to draw the statistics. If not, you need
> a loop or some other way to create the first vector initially.
>
> --

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us