查看单个帖子
旧 2008-10-16, 18:27   #2
meteora1005
高级会员
 
注册日期: 2008-05-31
年龄: 38
帖子: 104
声望力: 19
meteora1005 正向着好的方向发展
默认 回复: [求助]作一个填色的方块图,对应一个数字矩阵

程序免费给你编了,代码和结果如下:
function shiyan(a)
%互补色方格图

b=flipud(a);
n=size(b);
[y x]=find(b);
len=length(y);

figure(1);
for i=1:len
shiyansub(x(i),y(i),'b');
end

[y0 x0]=find(b==0);
len0=length(y0);
for i=1:len0
shiyansub(x0(i),y0(i),'r');
end

set(gca,'XTick',0:n,'YTick',0:n);
grid on;
set(gca,'GridLineStyle','-','YTickLabel',[],'XTickLabel',[]);

%----------------------------------------------------------shiyansub
function shiyansub(x,y,color)

tt=[x x x-1 x-1];
yy=[y y-1 y-1 y];
fill(tt,yy,color);
hold on;
%-------------------------------------------------------------endsub
测试:
a=
0 0 1 1 0 1 1 1 0 0
0 0 1 0 0 1 0 0 1 0
1 1 0 1 1 1 0 1 0 0
0 0 0 0 1 0 1 1 0 1
1 1 0 1 1 1 0 1 0 1
0 1 1 0 0 1 1 1 1 1
1 1 0 1 1 0 1 0 1 0
1 0 0 0 0 0 0 1 1 1
1 0 1 0 1 0 0 0 0 0
1 1 1 0 0 0 0 1 1 0
图:
上传的图像
文件类型: jpg 01.jpg (24.2 KB, 14 次查看)
meteora1005 当前离线   回复时引用此帖