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:
Problem with pcolor

Subject: Problem with pcolor

From: Hermano Cappa

Date: 10 Aug, 2011 15:35:31

Message: 1 of 4

Hi,

I want to plot a matrix A which has values '1' and '0' with pcolor. If the value is '1' I want the cell to be coloured green, and red if the value is '0'. If A = [1 1; 0 0] and I plot this matrix with pcolor I only get a window which is totaly red. Normally the upper right and upper left corners must be different coloured then the bottom left and bottom right cornes. If I check the help file, there is an example with 'pcolor(hadamard(20))' however also there the 'checkerboard' has a 19 x19 dimension instead of 20x20. Any a solution or alternative for this problem?

Subject: Problem with pcolor

From: Image Analyst

Date: 11 Aug, 2011 02:25:28

Message: 2 of 4

Hermano Cappa:
That's why I don't use that weird function. Why are you? Not to mention the fact that it shows one less colored square than elements across or down that you have. You'll be better off using imshow() or image(), or imagesc(). That's my recommended order of using the built-in display functions.

Subject: Problem with pcolor

From: Hermano Cappa

Date: 11 Aug, 2011 07:22:28

Message: 3 of 4

"Image Analyst" wrote in message <j1veio$6de$1@newscl01ah.mathworks.com>...
> Hermano Cappa:
> That's why I don't use that weird function. Why are you? Not to mention the fact that it shows one less colored square than elements across or down that you have. You'll be better off using imshow() or image(), or imagesc(). That's my recommended order of using the built-in display functions.

Image Analyst: Thanks for your fast response! I didn't know that it was that easy with the imshow() function. One question: Is it possible to generate a grid in such a way that the colour of one cell lies between the grid lines?

Thanks

Steven

Subject: Problem with pcolor

From: Hermano Cappa

Date: 11 Aug, 2011 10:04:13

Message: 4 of 4

Image Analyst can you help me with another problem I'm facing?? I want to place the x- and yticklabels between the x- and y-ticks. I wrote a short program to test this but it won't work for the x-axis. Also a white space appears suddenly on my figure. Any suggestion?

This is my program:

A =[1 0; 0 0; 1 1];
[I,J] = size(A);
alphatick = 0.5:1:I+1;
betatick = 0.5:1:J+1;
alphapos = 0.5*diff(alphatick)+alphatick(1:end-1);
betapos = 0.5*diff(betatick)+betatick(1:end-1);
alphalabels = [10:10:30];
betalabels = [100:100:200]';

figure
fig(1)=newplot;
set(gcf,'nextplot','add');
set(fig(1),'Ylim',[0.5,3.5],'YTick',alphapos,'YTicklabel',alphalabels);
set(fig(1),'Xlim',[0.5,2.5],'XTick',betapos,'XTicklabel',betalabels);
fig(2)=axes('position',get(fig(1),'position'),'Visible', 'off');
imshow(A,'InitialMagnification','fit')
iptsetpref('ImshowAxesVisible','on');
cmap(1,:) = [1 0 0]; % Green for 1
cmap(2,:) = [0 1 0]; % Red for 0
colormap(cmap);
set(fig(2),'Ylim',[0.5,3.5],'YTick',alphatick,'YTicklabel','');
set(fig(2),'Xlim',[0.5,2.5],'XTick',betatick,'XTicklabel','');
grid on

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