matlab bar 填充花纹,Matlab中画花纹填充的柱状图_晒月亮的孩子的博客-程序员宅基地

技术标签: matlab bar 填充花纹  

在画柱状图时,利用不同的颜色区分在实际打印时经常区分不出。

为了能够更清楚第表示最终结果,可采用在柱状图中打阴影的方式来表示。

然而,Matalab本身没有提供实现这种功能的函数库。

下面两个函数:

% ApplyBrandon

's function

applyhatch_pluscolor

% Apply Brian'sfunction

applyhatch_plusC(fH,'\-x.', 'rkbk');

实现了上述功能。

这两个函数中都调用了函数makehatch_plus源码如下(都已经调试通过,可方便使用)。

h = bar(rand(3,4));

%随机生成3行4列的矩阵

fH = gcf;

colormap(jet(4));

%参数4表示4列数的颜色

legend('Apple', 'Orange', 'Banana','Melon', 'Location',

'EastOutside');

% Apply

Brandon'sfunction(PS:接着上面的代码写)

tH = title('Brandon''s applyhatch');

applyhatch_pluscolor(fH,'\-x.', 0, [1 0 1 0], jet(4));

%参数4可改变

% Apply Brian'sfunction

set(tH, 'String','Brian''s applyhatch');

applyhatch_plusC(fH,'\-x.', 'rkbk');

set(tH, 'String','Original');

代码源自:

http://www.mathworks.com/matlabcentral/fileexchange/24021-hatch-fill-patterns-plus-color-invert/content/applyhatch_pluscolor.m

function[im_hatch,colorlist] =

applyhatch_pluscolor(h,patterns,CvBW,Hinvert,colorlist,...

dpi,hatchsc,lw)

%APPLYHATCH_PLUSCOLORApply hatched patterns to a figure in

BW or Color

%  APPLYHATCH_PLUSCOLOR(H,PATTERNS)

creates anew figure from the figure H by

%  replacing distinct colors in H with

the blackand white

%  patterns in PATTERNS. The format for

PATTERNScan be

%    a

string of the characters:

%

'/', '\', '|', '-', '+', 'x', '.', 'c','w', 'k'

%

(see makehatch_plus.m for more details) or

%    a

cell array of matrices of zeros (white) andones (black)

%

%  In addition, H can alternatively be a

uint8NxMx3 matrix of the type

%  produced by imread.

In this case, colors in this image will be

%  replaced with patterns as if it was

afigure.  A final figure window

%  will be generated that displays

theresult.  The DPI argument

%  discussed below will be ignored if H

is animage matrix.

%

%  APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW)

binaryvalue for choice of Color or Black

%  and White plots. If color is chosen

the colorwill match that of the

%  current fill. 1 ->

Color, anything else-> BW

%

%

APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT)binary value to invert

the hatch.

%  i.e., if it is black lines with a

whitebackground, that becomes white

%  lines with a black background. This

can eitherbe a scalar value or a

%  1xN array equal to the length of

PATTERNS.When used as an array each

%  PATTERNS(i) will be inverted according

toHinvert(i). 1 -> Invert,

%  anything else -> Non

Inverted

%

% APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT,COLORS)

maps the colors inthe n by 3

%  matrix COLORS to PATTERNS. Each row of

COLORSspecifies an RGB

%  color value.

%

%  Note this function makes a bitmap

image of Hand so is limited

%  to bitmap output.

%

%  Additional arguments:

%

%  [im_hatch,colorlist]

=applyhatch_plus(h,patterns,CvBW,Hinvert,colorlist,dpi,hatchsc,linewidth)

%

%

input  DPI

allows specificationof bitmap resolution, making plot

resolution

%

better forprinting.  Ignored if H is an

imagematrix.

%

HATCHSC    multiplier

for hatch scale to increase size of pattern for

betteroperation

%

at higher resolutions

%

default [] uses screenresolution as in

%

APPLYHATCH

%

LINEWIDTH   A scaling factor to

apply to line and dotsizes

%

in hatching.  Defaults to 1.

%

output IM_HATCH

RGB bitmap matrix ofnew figure

%

use IMWRITE to output indesired format

%

COLORLIST   List of colors

actually replaced.  Useful info if

%

no colorlist initiallygiven to function.

%

Colorlist will be uint8,not 0-1 scale as

%

originally specified.

%

%  Example 1:

%

bar(rand(3,4));

%

[im_hatch,colorlist]

=applyhatch_pluscolor(gcf,'\-x.',0,0,[],150);

%

imwrite(im_hatch,'im_hatch.png','png')

%

%  Example 2:

%

bar(rand(3,4));

%

[im_hatch,colorlist]

=applyhatch_pluscolor(gcf,'\-x.',1,[],[],150);

%

imwrite(im_hatch,'im_hatch.png','png')

%

%  Example 3:

%

colormap(cool(6));

%

pie(rand(6,1));

%   legend('Jan','Feb','Mar','Apr','May','Jun');

%

im_hatch =applyhatch_pluscolor(gcf,'|-.+\/',1,[1 1 0 1 0

0],cool(6),200,3,2);

%

imwrite(im_hatch,'im_hatch.png','png')

%

%  Example 4: Produces roughly the same

thing asexample 1

%

bar(rand(3,4));

%

print -dtiff -r150 im.tiff

%    im

= imread( 'im.tiff', 'tiff' );

%

[im_hatch,colorlist] =applyhatch_pluscolor(im,'\-x.');

%

imwrite(im_hatch,'im_hatch.tiff','tiff')

%

%

% Modification ofAPPLYHATCH to allow higher resolution

output

% Modified Brian

FGKatz

8-aout-03

% Modified David

MKaplan

19-fevrier-08

%

% Modification ofAPPLYHATCH_PLUS to allow for color and

inverted hatch

% ModifiedBrandon

Levey  May 6, 2009

%

%  See also: APPLYHATCH,

APPLYHATCH_PLUS,MAKEHATCH, MAKEHATCH_PLUS

%  By Ben Hinkle,

[email protected]

%  This code is in the public

domain.

if~exist('CvBW','var'); CvBW =

0

;end  % defaults to black and white

if isempty(CvBW);CvBW =

0

; end  % defaults to black and white

if (CvBW ~= 0&& CvBW ~=

1); CvBW =

0

;end  % defaults to black and white

if~exist('Hinvert','var'); Hinvert =

0     ;

end  % defaults to not inverted

ifisempty(Hinvert); Hinvert =

0

; end  % defaults to not inverted

if length(Hinvert)== length(patterns) || length(Hinvert)

== 1

for

i = 1:length(Hinvert)

if Hinvert(i) ~= 0 &&Hinvert(i) ~=

1; Hinvert(i) =

0

; end

end

else

error(['The length of Hinvert must be 1 orequal to the length of

PATTERNS']);

end

if~exist('hatchsc','var'); hatchsc =

1     ;

end

if~exist('dpi','var'); dpi =

0

;end

% defaults to screen resolution

if~exist('colorlist','var'); colorlist =

[]  ; end

if~exist('lw','var'); lw=1; end

if numel(h) == 1 %Assume it is a figure window

oldppmode =

get(h,'paperpositionmode');

oldunits = get(h,'units');

oldcolor = get(h,'color');

oldpos = get(h,'position');

set(h,'paperpositionmode','auto');

set(h,'units','pixels');

set(h,'color',[1 1 1]);

figsize = get(h,'position');

bits =

hardcopy(h,'-dzbuffer',['-r'num2str(dpi)]);

% % Try a different approach using

atemporary file - use this if having probs

% tn = [ tempname '.tif' ];

% print( '-dtiff', [ '-r' num2str(dpi)

], tn)

% bits = uint8( imread( tn, 'TIFF' )

);

% delete(tn)

set(h,'paperpositionmode',oldppmode);

set(h,'color',oldcolor);

elseif size(h,3) ==3 % Assume it is an image

matrix

bits = h;

oldunits='pixels';

oldpos = [ 0, 0, size(bits,2),

size(bits,1)];

figsize = oldpos;

else

error( 'Bad first argument.'

);

end

bwidth =size(bits,2);

bheight =size(bits,1);

bsize = bwidth *bheight;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The next bitbasically modernizes the original

% version of thisfunction using things like

unique

% and for loops

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Make bitmap onelong matrix with 3 columns

bits =reshape(bits,[bsize,3]);

% Convert originalcolor scale to 255 scale

if~isempty(colorlist)

% NOTE: Added "floor" below becausethis

seems to better pick out

% correct colors produced by

"hardcopyabove better than uint8 by itself

%colorlist =

uint8(255*colorlist);

colorlist =

uint8(floor(255*colorlist));

else

% Find unique colors in image - this

takes along time at high resolution

[B,I,J] = unique( bits, 'rows'

);

switch CvBW

case 0 % BW plot

% Find just "colored" colors

C = find( B(:,1)~=B(:,2) |B(:,1)~=B(:,3) );

case 1 % color plot

% Find all non black and white

B = sortrows(B);

C = 1:size(B,1);

C = C(2:end-1)';

end

colorlist = B( C , : );

end

% Loop over list ofcolors and find matches

for k =1:size(colorlist,1)

% Find points that match

color

if exist('B','var') % Use unique colors

ifaround

I =

C(k) == J;

else % Otherwise test each

point

cc

= colorlist(k,:);

I =

bits(:,1)==cc(1) &

bits(:,2)==cc(2)& bits(:,3)==cc(3);

if

~any(I(:)), continue, end

end

% What pattern to use

pati = mod( k-1, numel(patterns) ) +

1;

if iscell(patterns)

pattern = patterns{pati};

elseif isa(patterns,'char')

pattern =makehatch_plus(patterns(pati),6*hatchsc,lw);

else

pattern = patterns;

end

pattern = uint8(1-pattern);

if length(Hinvert) == 1

invertHatch = logical(Hinvert);

else

invertHatch = logical(Hinvert(pati));

end

% Make a big pattern matching size of

bits

pheight = size(pattern,2);

pwidth = size(pattern,1);

ratioh =

ceil(bheight/pheight);

ratiow =

ceil(bwidth/pwidth);

bigpattern = repmat(pattern,[ratioh

ratiow]);

if ratioh*pheight >

bheight

bigpattern(bheight+1:end,:) = [];

end

if ratiow*pwidth >

bwidth

bigpattern(:,bwidth+1:end) = [];

end

% Put that pattern into bits and

logicalvalues based on CvBW and Hinvert

switch CvBW

case 0 % BW

if invertHatch

bits(find(I),:) =repmat(~bigpattern(I)*255,[1,3]);

else

bits(find(I),:) =repmat(bigpattern(I)*255,[1,3]);

end

case

1 % Color

if invertHatch

bits(find(I),:) = [ ...

(uint8(bigpattern(I)) *colorlist(k,1)) + uint8((~bigpattern(I)) *

255), ...

(uint8(bigpattern(I)) *colorlist(k,2)) + uint8((~bigpattern(I)) *

255), ...

(uint8(bigpattern(I)) *colorlist(k,3)) + uint8((~bigpattern(I)) *

255)];

else

bits(find(I),:) = [ ...

(uint8(~bigpattern(I)) *colorlist(k,1)) + uint8((bigpattern(I)) *

255), ...

(uint8(~bigpattern(I))

*colorlist(k,2)) + uint8((bigpattern(I)) * 255), ...

(uint8(~bigpattern(I)) *colorlist(k,3)) + uint8((bigpattern(I)) *

255)];

end

end

end

% Put bits backinto its normal shape

bits = reshape(bits, [bheight,bwidth,3] );

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Replot

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

newfig

=figure('units',oldunits,'visible','off');

imaxes =axes('parent',newfig,'units','pixels');

im = image(bits,'parent',imaxes);

%fpos =get(newfig,'position');

%set(newfig,'position',[fpos(1:2)figsize(3)

figsize(4)+1]);

set(newfig,'position',oldpos)

set(newfig,'units','pixels')

set(imaxes,'position',[00 figsize(3)

figsize(4)+1],'visible','off');

set(newfig,'visible','on');

set(newfig,'units','normalized');

set(imaxes,'units','normalized');

set(imaxes,'DataAspectRatio',[11

1],'DataAspectRatioMode','manual');

if nargout > 0,im_hatch = bits;

end

if nargout < 2,clear colorlist;

end

(PS:函数结束)

代码源自:

http://www.mathworks.com/matlabcentral/fileexchange/24021-hatch-fill-patterns-plus-color-invert/content/makehatch_plus.m

function A =

makehatch_plus(hatch,n,m)

%MAKEHATCH_PLUSPredefined hatch patterns

%

% Modification ofMAKEHATCH to allow for selection of

matrix size. Useful whe using

%   APPLYHATCH_PLUS with

higher resolutionoutput.

%

% input

(optional)N

size of hatch matrix (default = 6)

% input

(optional)M

width of lines and dots in hatching(default = 1)

%

%  MAKEHATCH_PLUS(HATCH,N,M) returns a

matrixwith the hatch pattern for HATCH

%   according to the

following table:

%

HATCH

pattern

%

-------

---------

%

/

right-slanted lines

%

\

left-slanted lines

%

|

vertical lines

%

-

horizontal lines

%

+

crossing vertical and horizontallines

%

x

criss-crossing lines

%

.

square dots

%

c

circular dots

%

w

Just a blank white pattern

%

k

Just a totally black pattern

%

%  See also: APPLYHATCH,

APPLYHATCH_PLUS,APPLYHATCH_PLUSCOLOR, MAKEHATCH

%  By Ben Hinkle,

[email protected]

%  This code is in the public

domain.

% Modified Brian

FGKatz

8-aout-03

% Modified David

MKaplan

19-fevrier-08

if~exist('n','var'), n = 6; end

if~exist('m','var'), m = 1; end

n=round(n);

switch (hatch)

case '\'

[B,C] = meshgrid( 0:n-1 );

B =

B-C;

clear C

A =

abs(B) <= m/2;

A =

A | abs(B-n) <= m/2;

A =

A | abs(B+n) <= m/2;

case '/'

A =

fliplr(makehatch_plus('\',n,m));

case '|'

A=zeros(n);

A(:,1:m) = 1;

case '-'

A =

makehatch_plus('|',n,m);

A =

A';

case '+'

A =

makehatch_plus('|',n,m);

A =

A | A';

case 'x'

A =

makehatch_plus('\',n,m);

A =

A | fliplr(A);

case '.'

A=zeros(n);

A(1:2*m,1:2*m)=1;

case 'c'

[B,C] = meshgrid( 0:n-1 );

A =

sqrt(B.^2+C.^2) <= m;

A =

A | fliplr(A) | flipud(A) |flipud(fliplr(A));

case 'w'

A =

zeros(n);

case 'k'

A =

ones(n);

otherwise

error(['Undefined hatch pattern "'hatch '".']);

end

代码源自

http://www.mathworks.com/matlabcentral/fileexchange/26797-applyhatchplusc/content/applyhatch_plusC.m

function im_hatchC=

applyhatch_plusC(h,patterns,patterncolors,colorlist,dpi,hatchsc)

%APPLYHATCH_PLUSCApply colored hatched patterns to a

figure

%  im_hatch

=applyhatch_plusC(h,patterns,patterncolors,colorlist,dpi,hatchsc)

%

%  APPLYHATCH_PLUSC(H,PATTERNS) creates a

newfigure from the figure H by

%  replacing distinct colors in H with

the blackand white

%  patterns in PATTERNS. The format for

PATTERNScan be

%    a

string of the characters '/', '\', '|','-', '+', 'x',

'.'

%    a

cell array of matrices of zeros (white)and ones (black)

%

%  By default the lines are of uniform

thickenss.hatch patterns line

%  thickness can be modified using a

direct callto MAKEHATCH_PLUS using

%  the following syntax:

makehatch_plus('HHn',m)where;

%

HH    thehatch character written

twice, '//', '\\', '||', '--', '++'

%

n  integer number for

thickness

%

m  integer number for the matrix

size (n<=m)

% Ex.makehatch_plus('\\4',9)

%

%  APPLYHATCH_PLUSC(H,PATTERNS,COLORS)

maps thecolors in the n by 3

%  matrix COLORS to PATTERNS. Each row of

COLORSspecifies an RGB

%  color value. COLORS can also be a

characterstring list.

%

%  Note this function makes a bitmap

image of Hand so is limited

%  to bitmap output.

%

%  Example 1: basic operation using color

charstring

%

bar(rand(3,6));

%

im_hatchC = applyhatch_plusC(1,'\-x.\x','rkgrgb');%

%

%  Example 2: basic operation using color

matrix

%

bar(rand(3,4));

%

im_hatchC = applyhatch_plusC(1,'\-x.',[10 0;0 1 0;0 0 1;0 1

1]);

%

%  Example 3: basic operation using

resolutionmodification

%

pie(rand(6,1));

%

legend('Jan','Feb','Mar','Apr','May','Jun');

%

im_hatch

=applyhatch_plusC(gcf,'|-+.\/','rgbcmy',[],150,0.5);

%

imwrite(im_hatch,'im_hatch.tiff','tiff')

%  Note : have not been able to

understandexactly how colors are assigned

%  for some plot functions, so better to

leaveCOLORLIST empty for

%  starters

%

%  Example 4: basic operation with user

definedpatterns

%

bar(rand(3,3));

%

im_hatch

=applyhatch_plusC(gcf,{makehatch_plus('\',6),1-makehatch_plus('\',6),makehatch_plus('\',1)},'ggg');%

%

% Example 5: usingvariable thickness hatches

%

bar(rand(3,3));

%

im_hatch

=applyhatch_plusC(gcf,{makehatch_plus('\',9),makehatch_plus('\\4',9),makehatch_plus('\\8',9)},'rgb');%

%

%  Example 6: basic operation using IMAGE

plot

%   data =

reshape([randperm(8) randperm(8)randperm(8)],4,6)

%

image(data)

%   im_hatch

=applyhatch_plusC(1,'|-+.\/x/','rgbcmykr',colormap);

% Note : do not useimagesc, as you need an indexed image

if you want to

% control the hatchassignments related to data

values.

%

% Modification ofAPPLYHATCH_PLUS to allow colored

patterns

% Modified Brian

FGKatz

25-feb-2010

%  im_hatch

=applyhatch_plusC(h,patterns,patterncolors,colorlist,dpi,hatchsc)

%

%

input  patterncolors

RGB matrix ofcolors for patterns

%

(length(PATTERNS)

X 3) orstring of color char

%

'r' 'g' 'b' 'c' 'm''y' of length = length(PATTERNS)

%

DPI

allows specification of bitmapresolution, making plot

resolution

%

better

for printing

%

HATCHSC

multiplier for hatch scale to increasesize of pattern for better

operation

%

at higherresolutions (not used when PATTERNS

%

defines pattern matrix)

%

default [] usesscreen resolution as in APPLYHATCH

%

output IM_HATCH

RGB bitmap matrixof new figure

%

use IMWRITE tooutput in desired format

%

% Modified Brian

FGKatz

21-sep-11

%   Variable line

thickness

%

%  See also: APPLYHATCH,

APPLYHATCH_PLUS

%  By Ben Hinkle,

[email protected]

%  This code is in the public

domain.

oldppmode =get(h,'paperpositionmode');

oldunits =get(h,'units');

oldcolor =get(h,'color');

oldpos = get(h,'position');

set(h,'paperpositionmode','auto');

set(h,'units','pixels');

set(h,'color',[1 11]);

figsize =get(h,'position');

if nargin < 6;hatchsc =

1

; end

if nargin < 5;dpi =

0

;

end

% defaults to screen resolution

if nargin < 4;colorlist =

[]   ; end

if length(patterns)~= length(patterncolors)

error('PATTERN and PATTERNCOLORS must bethe same

length')

end

ifischar(patterncolors),

patterncolors =charcolor2rgb(patterncolors);

end

bits =hardcopy(h,'-dzbuffer',['-r'

num2str(dpi)]);

bitsC = ones(size(bits))*0;

blackpixels

=intersect(find(bits(:,:,1)==255),(intersect(find(bits(:,:,1)==bits(:,:,2)),find(bits(:,:,1)==bits(:,:,3))))

) ;

set(h,'paperpositionmode',oldppmode);

set(h,'color',oldcolor);

bwidth = size(bits,2);

bheight =size(bits,1);

bsize = bwidth *bheight;

if~isempty(colorlist)

colorlist =

uint8(floor(255*colorlist));

[colors,colori]

=nextnonbw(0,colorlist,bits);

else

colors = (bits(:,:,1) ~= bits(:,:,2)) |

...

(bits(:,:,1) ~=

bits(:,:,3));

end

pati = 1;

colorind =find(colors);

while~isempty(colorind)

colorval(1) =

bits(colorind(1));

colorval(2) =

bits(colorind(1)+bsize);

colorval(3) =

bits(colorind(1)+2*bsize);

if iscell(patterns)

pattern = patterns{pati};

elseif isa(patterns,'char')

pattern =makehatch_plus(patterns(pati),6*hatchsc);

else

pattern = patterns;

end

patternC =

uint8(255*pattern);

pattern =

uint8(255*(1-pattern));

pheight = size(pattern,2);

pwidth = size(pattern,1);

ratioh =

ceil(bheight/pheight);

ratiow =

ceil(bwidth/pwidth);

bigpattern = repmat(pattern,[ratioh

ratiow]);

if ratioh*pheight >

bheight

bigpattern(bheight+1:end,:) = [];

end

if ratiow*pwidth >

bwidth

bigpattern(:,bwidth+1:end) = [];

end

bigpattern = repmat(bigpattern,[1 1

3]);

% Create RGB pattern

pat_size = size(pattern,1)*size(pattern,2);

pat_id = find(patternC);

patternCrgb =repmat(ones(size(patternC))*255,[1 1

3]) ;

for

rgbLOOP = 1:3,

patternCrgb(pat_id+(pat_size*(rgbLOOP-1)))=patternCrgb(pat_id+(pat_size*(rgbLOOP-1)))*patterncolors(pati,rgbLOOP);

end

% rgbLOOP

bigpatternC = repmat(patternCrgb,[ratiohratiow 1]);

bigpatternC

=bigpatternC(1:size(bigpattern,1),1:size(bigpattern,2),:)

;

%

if ratioh*pheight > bheight

%

bigpatternC(bheight+1:end,:,:) = [];

%

end

%

if ratiow*pwidth > bwidth

%

bigpatternC(:,bwidth+1:end,:) = [];

%

end

color = (bits(:,:,1) == colorval(1))

&...

(bits(:,:,2) == colorval(2)) &

...

(bits(:,:,3)== colorval(3));

color = repmat(color,[1 1

3]);

bits(color) =

bigpattern(color);

bitsC(color) = bigpatternC(color);

if ~isempty(colorlist)

[colors,colori] =nextnonbw(colori,colorlist,bits);

else

colors = (bits(:,:,1) ~= bits(:,:,2)) | ...

(bits(:,:,1)

~= bits(:,:,3));

end

colorind = find(colors);

pati = (pati + 1);

if pati >

length(patterns)

pati = 1;

end

end

bitsC(blackpixels)=255;

bitsC(blackpixels+(bheight*bwidth))=255;

bitsC(blackpixels+(2*(bheight*bwidth)))=255;

newfig

=figure('units','pixels','visible','off');

imaxes =axes('parent',newfig,'units','pixels');

im =image(bitsC/255,'parent',imaxes);

%fpos =get(newfig,'position');

%set(newfig,'position',[fpos(1:2)figsize(3)

figsize(4)+1]);

set(newfig,'position',oldpos)

set(imaxes,'position',[00 figsize(3)

figsize(4)+1],'visible','off');

set(newfig,'visible','on');

set(newfig,'units','normalized');

set(imaxes,'units','normalized');

set(imaxes,'DataAspectRatio',[11

1],'DataAspectRatioMode','manual');

if nargout

==1,

im_hatchC = bitsC; end

function[colors,out] = nextnonbw(ind

,colorlist,bits)

out =ind

+1;

colors = [];

while out <=size(colorlist,1)

if isequal(colorlist(out,:),[255 255

255]) |...

isequal(colorlist(out,:),[0 0 0])

out

= out+1;

else

colors = (colorlist(out,1) == bits(:,:,1))&

...

(colorlist(out,2)

== bits(:,:,2)) & ...

(colorlist(out,3)

== bits(:,:,3));

return

end

end

function colors_rgb=

charcolor2rgb(colors_char);

forLOOP

= 1:length(colors_char),

switch colors_char(LOOP

)

case 'r'

colors_rgb(LOOP,:) = [1 0

0]

;

case 'g'

colors_rgb(LOOP,:) = [0 1

0]

;

case 'b'

colors_rgb(LOOP,:) = [0 0

1]

;

case 'c'

colors_rgb(LOOP,:)

= [0 1 1]

;

case 'm'

colors_rgb(LOOP,:) = [1 0

1]

;

case 'y'

colors_rgb(LOOP,:) = [1 1

0]

;

case 'k'

colors_rgb(LOOP,:) = [0 0

0]

;

otherwise

error('Invalid folor char

string')

end

end

转自:http://www.doc88.com/p-6771119624572.html​

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_36475451/article/details/115887569

智能推荐

导出到excel,angular_蒲公英的博客-程序员宅基地_angular导出excel

效果:代码html:&lt;button title="导出" nz-button nzType="default" style="float: right" (click)="click()"&gt; &lt;i nz-icon nzType="export" nzTheme="outline"&gt;&lt;/i&gt;&lt;/button&gt;&lt;div class="table" #excel&gt; &lt;table&gt; …… &lt

摩拜单车小程序开发实践与框架分析_非著名程序员_的博客-程序员宅基地

以打造内容全、技术新、可实操的小程序小册为目标,整本小册共包含 21 节,不仅讲述了小程序开发的一些基础知识,也通过摩拜单车业务案例深入小程序开发,此外,还加入了主流框架...

MHA搭建MySQL高可用架构与故障修复_Mr. Root的博客-程序员宅基地

MHA集群搭建一,MHA介绍:  1,简介:MHA是一套解决MySQL高可用的架构,当数据库故障时,它能够在0~30s之内完成故障自动切换,保证数据库服务正常运行;在故障自动切换的过程中它能够最大限度的保障数据的一致性,这样真正意义上达到高可用.  2,组成:  MHA Manager(管理节点):管理所有数据库服务器,可以单独部署在一台服务器上,也可部署在某一台数据库服务器上  MHA...

linux java 串口_无法在linux中打开串口_书生夜行的博客-程序员宅基地

使用fedora 11,在连续课程中:/*\return 1 success\return -1 device not found\return -2 error while opening the device\return -3 error while getting port parameters\return -4 Speed (Bauds) not recognized\return -...

Egret Engine 2D - 矢量绘图_weixin_30487317的博客-程序员宅基地

绘制矩形drawRect绘制矩形边lineStyle( 10, 0x00ff00清空绘图clear绘制园形drawCircle绘制直线moveTolineTo绘制曲线cureTo(a b c d)a b设置是目标点的x yc d是中途拐点的x y...

int linux 原子操作_Linux下的原子操作_华雯婷的博客-程序员宅基地

linux支持的哪些操作是具有原子特性的?知道这些东西是理解和设计无锁化编程算法的基础。__sync_fetch_and_add系列的命令,发现这个系列命令讲的最好的一篇文章,英文好的同学可以直接去看原文。Multithreaded simple data type access and atomic variables__sync_fetch_and_add系列一共有十二个函数,有加/减/与/或...

随便推点

finereport连接oracle_FineReport连接多维数据库示例及操作_weixin_39726267的博客-程序员宅基地

1.描述FineReport连接多维数据库,首先要通过数据连接将多维数据库与FineReport连接起来,然后在数据连接的基础上新建多维数据库XMLA数据集,用于模板设计。2.XMLA数据连接2.1描述多维数据库(Multi Dimensional Database,MDD),顾名思义,就是指将数据存储在多个维度中,简单来说,就是将数据存放在一个n维数组中,而不是像关系据库那样以记录的形式存放。...

PyTorch 1.7发布,支持CUDA 11、Windows分布式训练_普通网友的博客-程序员宅基地

机器之心报道参与:魔王、小舟昨日,PyTorch 团队发布 PyTorch 1.7 版本。该版本增添了很多新特性,如支持 CUDA 11、Windows 分布式训练、增加了支持快速傅里叶变...

卫春芳计算机基础视频,第一章 计算机基础知识.pptx_ynjkl007的博客-程序员宅基地

文档介绍:大学计算机基础主讲:数计学院卫春芳所用教材:《大学计算机基础》科学出版社大学计算机基础高等教育出版社杨振山龚沛曾主编大学计算机基础(第4版)大学计算机基础实验教程(电子版)参考书目湖北大学→图书馆→馆藏资源→电子图书→中文数据库→超星电子图书→超星图书库→输入书名→搜索作者: 徐进华,钱毅湘等出版日期: 2011.632授课+32上机重点讲授计算机的基本原理、基本知识、基本方法,注...

DOS运行GHOST加参数_舞夜狂飙的博客-程序员宅基地

Ghost是一个典型的支持参数的DOS程序,充分利用它的参数,我们可以更好地控制Ghost。让它们更好地为我们工作,前面几个例子,我们就使用了Ghost的参数做出了一张自动备份和恢复硬盘数据的自启动光盘。正是因为Ghost参数众多,功能强大,我们才有必要把一些最最常用的参数列出,供大家平时参考使用。  提示:  (1)参数(Parameter)是程序提供给我们一些隐藏选项,通过添加

单行、多行输入框,其属性及功能场景_诗不姓的博客-程序员宅基地_android输入框单行

---单行输入框editText1.setSingleLine();editText1.setEms(10);editText1.setFilters(new InputFilter[] { new InputFilter.LengthFilter(5) });

人人都在讨论图数据库,它到底好在哪——创邻科技_创邻科技的博客-程序员宅基地_图数据库优缺点

人人都在讨论图数据库,它到底好在哪?【摘要】图数据库不是存储图片的数据库,而是存储顶点与他们之间关系的数据库。与传统关系型数据库相比,图数据库的优势体现在直观性、灵活性、高性能等方面。图数据库支持多种图算法,可以应用于社交网络、金融欺诈检测、实时推荐引擎、知识图谱、网络/IT运营等多个领域。随着近年来云计算、大数据、物联网等技术产业的快速发展,图数据库的使用率不断攀升,一些行业人士称图数据库是增长速度最快的数据库类型。如果说的是事实的话,那么我们了解它是非常有必要的。人们广泛提及的图数据库到底是什

推荐文章

热门文章

相关标签