Got Questions? Get Answers.
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:
Set colours in pcolor (plus include last line)

Subject: Set colours in pcolor (plus include last line)

From: Chris

Date: 13 Nov, 2009 00:02:03

Message: 1 of 2

Hi, I have created an m-file which outputs a matrix of integers. Currently the possibilities are 0, 1 or 2 but there could be more later. I want to create a grid of this matrix which has a different colour depending on each integer. have used pcolor but I cannot figure out how to assign a certain colour to each integer. An example:

A=ceil(3*rand(10))-1;
pcolor(A) %I would like zeros to appear green, ones: red and twos: black

I am aware that Matlab is interpreting each number as a point on the range between the minimum an maximum of the dataset, but I am only using integers (and will only use integers for this model).


Finally, is it possible to get Matlab to include the final row and column of the matrix in the pcolor plot?

Regards,
Chrs

Subject: Set colours in pcolor (plus include last line)

From: ImageAnalyst

Date: 13 Nov, 2009 01:59:17

Message: 2 of 2

On Nov 12, 7:02 pm, "Chris " <c.j.craws...@googlemail.com> wrote:
> Hi, I have created an m-file which outputs a matrix of integers. Currently the possibilities are 0, 1 or 2 but there could be more later. I want to create a grid of this matrix which has a different colour depending on each integer.  have used pcolor but I cannot figure out how to assign a certain colour to each integer. An example:
>
> A=ceil(3*rand(10))-1;
> pcolor(A) %I would like zeros to appear green, ones: red and twos: black
>
> I am aware that Matlab is interpreting each number as a point on the range between the minimum an maximum of the dataset, but I am only using integers (and will only use integers for this model).
>
> Finally, is it possible to get Matlab to include the final row and column of the matrix in the pcolor plot?
>
> Regards,
> Chrs
----------------------------------------------------------------------------------------------------------------
Chrs:
Try this:

workspace; % Show the Workspace panel.
% Make up some sample data having values of 0, 1, or 2.
imageArray = uint8(2 * rand(200));
% Make up a colormap to apply to it.
cmap(1,:) = [0 1 0]; % Green for 0
cmap(2,:) = [1 0 0]; % Red for 1
cmap(3,:) = [0 0 0]; % Black for 2.
% Display image with that colormap.
imshow(imageArray, cmap);
set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.

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