Now my code works as I want. Thank you for all the help. =) Below is the correct code.
filename= strcat('a.xlsx');
data=xlsread(filename);
for p=1:5
dataA=data(p,2:30)
dataB=data(p,31:59)
% for measure A
figure
subplot(2,1,1);
hold on
for k=1:length(dataA)
j=bar(k,dataA(k));
if dataA(k)==1 & dataB(k)==1
set(j,'FaceColor','b');
elseif dataA(k)==1 & dataB(k)==0
set(j,'FaceColor','r');
elseif dataA(k)==2 & dataB(k)==1
set(j,'FaceColor','k');
else
set(j,'FaceColor','y');
end
end
% for measure B
subplot(2,1,2);
hold on
for k=1:length(dataB)
j=bar(k,dataB(k));
if dataA(k)==1 & dataB(k)==1
set(j,'FaceColor','b)';
elseif dataA(k)==1 & dataB(k)==0
set(j,'FaceColor','r');
elseif dataA(k)==2 & dataB(k)==1
set(j,'FaceColor','k');
else
set(j,'FaceColor','y');
end
end
end