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:
Newbie problem

Subject: Newbie problem

From: David Craig

Date: 18 Nov, 2010 14:03:03

Message: 1 of 6

Hi,
I am trying to produce a grid with each cell color coded to a certain value. I have a 5 column matrix containing the max and min value of of latitude and longitude for each cell and the value I wish to associate with a color. I can produce the grid but cant figure out how to color code it. I think patch may suit this task but am having trouble using it, anyone any advice preferably in the form of an example or know where one is located, thanks.

Subject: Newbie problem

From: Steven_Lord

Date: 18 Nov, 2010 14:15:51

Message: 2 of 6



"David Craig" <dcdavemail@gmail.com> wrote in message
news:ic3bmn$78d$1@fred.mathworks.com...
> Hi,
> I am trying to produce a grid with each cell color coded to a certain
> value. I have a 5 column matrix containing the max and min value of of
> latitude and longitude for each cell and the value I wish to associate
> with a color. I can produce the grid but cant figure out how to color code
> it. I think patch may suit this task but am having trouble using it,
> anyone any advice preferably in the form of an example or know where one
> is located, thanks.

Are you looking for the functionality that PCOLOR provides?

If not, can you show us a small sample of data (say 5-by-5) and your attempt
to use PATCH to do what you want? If so it's entirely possible that someone
can help you with the PATCH syntax.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Newbie problem

From: PLH

Date: 18 Nov, 2010 14:28:05

Message: 3 of 6

So, to clarify: You have some XY pairs that you want to associate a colour (a number) with? For example, latitude and longitude (the XY pairs), with some associated colour (number) that might be "is land" (green) or " is not land" (blue)?

Then

N1 = 12;
N2 = 13;
Lat = linspace(0,2*pi,N1);
Long = linspace(0,2*pi,N2);
LandOrSea = round(rand(N1,N2)); % random matrix of 1s and 0s

pcolor(Long,Lat,LandOrSea);shading flat

Something like that? It's the same for more than 2 colours, Matlab just automatically bins the third value (the colour value) and selects the colour from the colourmap.

Subject: Newbie problem

From: David Craig

Date: 18 Nov, 2010 20:03:03

Message: 4 of 6

"PLH " <paulhalkyard@googlemail.com> wrote in message <ic3d5l$e4j$1@fred.mathworks.com>...
> So, to clarify: You have some XY pairs that you want to associate a colour (a number) with? For example, latitude and longitude (the XY pairs), with some associated colour (number) that might be "is land" (green) or " is not land" (blue)?
>
> Then
>
> N1 = 12;
> N2 = 13;
> Lat = linspace(0,2*pi,N1);
> Long = linspace(0,2*pi,N2);
> LandOrSea = round(rand(N1,N2)); % random matrix of 1s and 0s
>
> pcolor(Long,Lat,LandOrSea);shading flat
>
> Something like that? It's the same for more than 2 colours, Matlab just automatically bins the third value (the colour value) and selects the colour from the colourmap.

pcolor seems to be just what I need,
an example of my data is,
   96.1413 1.4283 0.1200
   96.1413 1.6283 0.2400
   96.1413 1.8283 0.1600
   96.1413 2.0283 0.1600
   96.1413 2.2283 0.2000
the first and second columns giving Lat and Long for the centre points of each cell in a grid and the third a value for stress in that cell. PLH's method would be just what I need I tried the following but it doesnt work as the color input is not a matrix and I am not sure how to generate one correctly,

a=[bev(330:334,1),bev(330:334,2),bev(330:334,5)];
Lat = a(:,2);
Long = a(:,1);
Coupling = [a(:,3)];
pcolor(Long,Lat,Coupling);shading flat

Subject: Newbie problem

From: David Craig

Date: 18 Nov, 2010 23:05:06

Message: 5 of 6

"David Craig" <dcdavemail@gmail.com> wrote in message <ic40pn$1k8$1@fred.mathworks.com>...
> "PLH " <paulhalkyard@googlemail.com> wrote in message <ic3d5l$e4j$1@fred.mathworks.com>...
> > So, to clarify: You have some XY pairs that you want to associate a colour (a number) with? For example, latitude and longitude (the XY pairs), with some associated colour (number) that might be "is land" (green) or " is not land" (blue)?
> >
> > Then
> >
> > N1 = 12;
> > N2 = 13;
> > Lat = linspace(0,2*pi,N1);
> > Long = linspace(0,2*pi,N2);
> > LandOrSea = round(rand(N1,N2)); % random matrix of 1s and 0s
> >
> > pcolor(Long,Lat,LandOrSea);shading flat
> >
> > Something like that? It's the same for more than 2 colours, Matlab just automatically bins the third value (the colour value) and selects the colour from the colourmap.
>
> pcolor seems to be just what I need,
> an example of my data is,
> 96.1413 1.4283 0.1200
> 96.1413 1.6283 0.2400
> 96.1413 1.8283 0.1600
> 96.1413 2.0283 0.1600
> 96.1413 2.2283 0.2000
> the first and second columns giving Lat and Long for the centre points of each cell in a grid and the third a value for stress in that cell. PLH's method would be just what I need I tried the following but it doesnt work as the color input is not a matrix and I am not sure how to generate one correctly,
>
> a=[bev(330:334,1),bev(330:334,2),bev(330:334,5)];
> Lat = a(:,2);
> Long = a(:,1);
> Coupling = [a(:,3)];
> pcolor(Long,Lat,Coupling);shading flat

Have got a little further in that I think I have applied my lat/long to this properly but am still a bit unsure I have assigned the color correctly. My data is in the form of three columns with 2508 rows, the first 57 rows represent a constant longitude (x-axis) and the second is increasing latitude. The third column is the color value heres what I have done,

Coupling=zeros(57,44);
Lat = bev(1:57,2);
Long = bev(1:57:2508,1);
n=1;

for i=1:44
    
    Coupling(:,i) = bev(n:n+56,5);
    n=n+57;
end

pcolor(Long,Lat,Coupling);shading interp

Subject: Newbie problem

From: ImageAnalyst

Date: 19 Nov, 2010 03:26:04

Message: 6 of 6

Be aware that pcolor will give you one less colored patch than
elements. For example, a 5x8 array will show up as 4 by 7 colored
squares.

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