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:
Assign color in plot based on value

Subject: Assign color in plot based on value

From: fas

Date: 4 Jan, 2010 06:38:25

Message: 1 of 2

I have a 50x50 matrix(A) with different values 1,2 , 5, 6, 9. I am
trying to display each value with different color.

I have tried 'imagesc' but it is random. I would myself like to assign
color based on values from matrix then like to display it using
imagesc. e.g A(A==5).... A(A== 2)....
So that I get a segmented image of different values which is based on
the colors I assign.

Any help ??? or code snippet ?.

Subject: Assign color in plot based on value

From: us

Date: 4 Jan, 2010 07:47:02

Message: 2 of 2

fas <faisalmufti@gmail.com> wrote in message <355095e6-94ae-4675-beba-97ba58ebbd88@b2g2000yqi.googlegroups.com>...
> I have a 50x50 matrix(A) with different values 1,2 , 5, 6, 9. I am
> trying to display each value with different color.
>
> I have tried 'imagesc' but it is random. I would myself like to assign
> color based on values from matrix then like to display it using
> imagesc. e.g A(A==5).... A(A== 2)....
> So that I get a segmented image of different values which is based on
> the colors I assign.
>
> Any help ??? or code snippet ?.

one of the solutions
- define and apply your colormap...

     img=magic(2);
     cmap=[
          1 0 0
          0 1 0
          0 0 1
          1 1 0
     ];
     imagesc(img);
     axis image;
     colormap(cmap);
     colorbar;

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