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 colors

Subject: plotting colors

From: ronnie

Date: 28 Jun, 2010 16:45:15

Message: 1 of 6

Hi, I have 3 sets of data to plot. two of the sets are time and numerical data which go on the x and y axis respectively. The other set of data is degree values (0 to 180 degreees). I want to plot a line on a graph and I want that line to be red if the data is above 45 degrees (the degree data that corresponds to the numerical data). Otherwise i want the line to be green. I only want one line on the graph. Is there any simple way to do this?

Subject: plotting colors

From: us

Date: 28 Jun, 2010 17:04:08

Message: 2 of 6

ronnie <asdfessssy@aol.com> wrote in message <321198735.17645.1277743545983.JavaMail.root@gallium.mathforum.org>...
> Hi, I have 3 sets of data to plot. two of the sets are time and numerical data which go on the x and y axis respectively. The other set of data is degree values (0 to 180 degreees). I want to plot a line on a graph and I want that line to be red if the data is above 45 degrees (the degree data that corresponds to the numerical data). Otherwise i want the line to be green. I only want one line on the graph. Is there any simple way to do this?

one of the many solutions
- as a skeleton...

     x=0:5:180;
     y=sind(x);
     ix=x>=45;
     line(x(ix),y(ix),'marker','s','color',[1,0,0]);
     line(x(~ix),y(~ix),'marker','o','color',[0,1,0]);

us

Subject: plotting colors

From: sscnekro

Date: 28 Jun, 2010 17:13:09

Message: 3 of 6

> Hi, I have 3 sets of data to plot. two of the sets are time and numerical data which go on the x and y axis respectively. The other set of data is degree values (0 to 180 degreees).

So do you need in fact a 3D plot, with x - time, y - numerical data, z - degree values? Maybe plot3() could be of help to you? Otherwise, you could use just plot()...

> I want to plot a line on a graph and I want that line to be red if the data is above 45 degrees (the degree data that corresponds to the numerical data). Otherwise i want the line to be green. I only want one line on the graph.

I'm not sure if I can imagine what you mean by this. Normally the line connects at least two points. How do you relate the degree value to your other data? Can you perhaps hang a picture of the grahp you need at http://imageshack.us/ or http://drop.io/

Subject: plotting colors

From: sscnekro

Date: 28 Jun, 2010 17:20:36

Message: 4 of 6

> x=0:5:180;
> y=sind(x);
> ix=x>=45;
> line(x(ix),y(ix),'marker','s','color',[1,0,0]);
> line(x(~ix),y(~ix),'marker','o','color',[0,1,0]);

Pardon, us, I would never dare to post after your post has been displayed on my screen. To your code, I just say: Wow! Please disregard my question above.

Subject: plotting colors

From: ronnie

Date: 28 Jun, 2010 17:55:09

Message: 5 of 6

ok ill show you exactly what I mean,

3 sets of data:

time = seconds, degree data and numerical data

(time, deg and num are stored in a seperate array each)

time, deg, num
1, 45, 10
2, 56, 20
3, 90, 30
4, 23, 40
5, 34, 50
6, 145, 60
7, 22, 70


what I want would be a line that goes from 10 to 70 while time on the x axis goes from 1 to 7 seconds.

that line would be red only when the corresponding degree values were greater than or equal to 45 degrees and green when the corresponding degree value was less than 45 degrees.

The end result would be a line graph that is both red and green.

Subject: plotting colors

From: sscnekro

Date: 29 Jun, 2010 02:33:06

Message: 6 of 6

> ok ill show you exactly what I mean,
> 3 sets of data:
> time, deg, num

Okay, ronnie. A must reading for you:
http://www.cs.bilkent.edu.tr/~duygulu/Courses/CS111/Notes/LogicalAndRelationalOperators.pdf

A PS just whispered .. is this what you wanted?

x = [1;2;3;4;5;6;7]; % time
y = [10;20;30;40;50;60;70]; % num
deg = [45;56;90;23;34;145;22];
iy = (deg >= 45); % create logical
line(x(iy),y(iy),'marker','s','color',[1,0,0]);
line(x(~iy),y(~iy),'marker','o','color',[0,1,0]);

Thanks, us.

Tags for 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