下面就是重点:如何把上述图像转换成黑白图像,并填充不同条纹。
首先,创建名为“applyhatch.m”的函数脚本。
在同一路径下。
代码如下:——复制即可。
function applyhatch(h,patterns,colorlist) %APPLYHATCH Apply hatched patterns to a figure % APPLYHATCH(H,PATTERNS) creates a new figure from the figure H by % replacing distinct colors in H with the black and white % patterns in PATTERNS. The format for PATTERNS can be % a string of the characters '/', '\', '|', '-', '+', 'x', '.' % a cell array of matrices of zeros (white) and ones (black) % % APPLYHATCH(H,PATTERNS,COLORS) maps the colors in the n by 3 % matrix COLORS to PATTERNS. Each row of COLORS specifies an RGB % color value. % % Note this function makes a bitmap image of H and so is limited % to low-resolution, bitmap output. % % Example 1: % bar(rand(3,4)); % applyhatch(gcf,'\-x.'); % % Example 2: % colormap(coo