How can I make gray or black color in circle?

6 views (last 30 days)
Haksun Lee
Haksun Lee on 4 Jul 2014
Commented: Image Analyst on 4 Jul 2014
As the following source, I made ring including some colors..
But I can't get black or gray color.
How can I make gray or black color in circle?
By which data can color affected?
%# define the ring
phi = linspace(0,2*pi,360);
innerRim = [cos(phi)',sin(phi)'];
outerRim = [cos(phi)',sin(phi)']*1.1;
xRing = [outerRim(:,1),innerRim(:,1),innerRim([2:end,1],1),outerRim([2:end,1],1)]';
yRing = [outerRim(:,2),innerRim(:,2),innerRim([2:end,1],2),outerRim([2:end,2],2)]';
%# create some data. 0 for black 0.5 for gray.
%# RingData has a value for each degree
ringData = ones(1,360);
ringData(1:40) =0.9;
ringData(40:80) = 0.8;
ringData(80:120) =0.7;
ringData(120:160) = 0.6;
ringData(160:200) = 0.4;
ringData(200:240) = 0.3;
ringData(240:280) = 0.2;
ringData(280:320) = 0.1;
ringData(320:360) = 0;
%# plot the ring
%# for an outer ring, add 1 to xRing, yRing
figure
patch(xRing,yRing,ringData, 'Edgecolor','none');
set(gca,'cLim',[0 1]);
axis square
axis off
set(gcf,'color','w');

Answers (1)

Image Analyst
Image Analyst on 4 Jul 2014
Add this code to the end of yours:
numberOfGrayLevels = 256; % from 1 to 256.
colormap(gray(numberOfGrayLevels));
colorbar;
  2 Comments
Image Analyst
Image Analyst on 4 Jul 2014
Yes, you can make up a custom colormap. For example you can say
colorMap = gray(256);
and if you want values of 30 to be [3 17 34] , just do
colorMap(31,:) = [3 17 34];
See caxis() to see how you can assign specific values of your data to row 1 and row 256 of your colormap.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!