1到100的数字分为四类，如何在10*10的图片上按照类别显示不同颜色？

``````clc;
clear;
close all;
A=[8,10,50,51,52,53,54,55,56,57,58,59,60,61];
B=[4,5,6,7,11,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,33];
C=[9,22,67,68,69,70,71,72,73,74,75,76,77,78,79,80];
D=[1,2,3,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,62,63,64,65,66,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]

rgb_R=zeros(10,10);
rgb_G=zeros(10,10);
rgb_B=zeros(10,10);

if A[]
rgb_R=1;rgb_G=0;rgb_B=0;%A为红色
end
if B[]
rgb_R=0;rgb_G=1;rgb_B=0;%B为绿色
end
if C[]
red_R=0;rgb_G=0;rgb_B=1;%C为蓝色
else  %D类
rgb_R=1;rgb_G=1;rgb_B=1;%D为白色
end
red=uint8(rgb_R);
green=uint8(rgb_G);
blue=uint8(rgb_B);

h=cat(3,red,green,blue);
I=imshow(h);
``````

1个回答

if语句应该写错了吧，以下是我写的，可以参考一下。

``````clc;
clear;
close all;
A=[8,10,50,51,52,53,54,55,56,57,58,59,60,61];
B=[4,5,6,7,11,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,33];
C=[9,22,67,68,69,70,71,72,73,74,75,76,77,78,79,80];
D=[1,2,3,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,62,63,64,65,66,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100];
rgb_R=zeros(100,1);
rgb_G=zeros(100,1);
rgb_B=zeros(100,1);
rgb_R(A,:)=1;
rgb_G(A,:)=0;
rgb_B(A,:)=0;
rgb_R(B,:)=0;
rgb_G(B,:)=1;
rgb_B(B,:)=0;
rgb_R(C,:)=0;
rgb_G(C,:)=0;
rgb_B(C,:)=1;
rgb_R(D,:)=0;
rgb_G(D,:)=0;
rgb_B(D,:)=1;
red=reshape(rgb_R,[10,10]);
green=reshape(rgb_G,[10,10]);
blue=reshape(rgb_B,[10,10]);
h=cat(3,red,green,blue);
I=imshow(h);
``````
innocentQ 太厉害了！十分感谢!!!!!我可以好好琢磨一下了！