问题:如何根据代码中稍后进行数学比较来更改每个单独的栏edgecolor
(我们有两个条形图f3和f4,每个条形图编号条形取决于rowNosMaxSG
,其中最大值将由14条组成。
目前使用下面的数学if语句来更改edgecolor
,遗憾的是,在执行每个3-if语句之后,我遇到了边缘颜色重叠,这种重叠会影响每个图形的整个条形,我希望能够根据数学比较控制每个条形图中每个条形的edgecolor
。
截断代码(包括数学比较):
f3= bar(SN, Shift_Grade', 'stacked', 'FaceColor', 'white');
f4= bar( SN( Shift_Gradey ~= 0 ), Shift_Gradey( Shift_Gradey ~= 0 ),...
'stacked', 'FaceColor', 'white', 'EdgeColor','green',...
'LineWidth', 2);
%---------------- **Mathematical-Comparison (3-if-statements)** --------------------
if ( SN( Shift_Grade' <= 11.3 )
set(f3, 'EdgeColor', 'r')
end
if ( SN( 11.3 < Shift_Grade' ) & SN( Shift_Grade' < 16 ) )
set(f3, 'EdgeColor', 'y')
end
if ( SN( Shift_Grade' >= 16 ) )
set(f3, 'EdgeColor', 'g')
set(f4, 'EdgeColor', 'g')
end
set(gca, 'Xtick', 1:2:length(SN)+1)
set(gca,'YLim',[0 20])
set(gca,'XLim',[0 length(SN)+1])
希望有一个清晰明确的答案来解决阻碍我进步的问题。感谢您提前的时间。
好主意Doresoom,我不知道。我已经实现了您的想法,但我仍然在下面的代码中收到此错误:
???使用==&gt;时出错set
无法从double
转换为cell
。
可重复代码:
SN= [1:14]';
SG= [15.5; 13; 15; 12.2; 13.6; 13.4; 14.2; 9; 17.7; 15; 12.5; 10; 16; 13.6];
SN_UnderDogs= [8; 12];
SN_Mediocre= [1; 2; 3; 4; 5; 6; 7; 10; 11; 14];
SN_Top= [9; 13];
for cc = 1:length(SN)
f3(cc) = bar(cc, SG(cc), 'FaceColor', 'white');
end
if SN( SG <= 11.3 )
for SNUD = SN_UnderDogs ( 1 : length (SN_UnderDogs) )
set(get(f3(SNUD),'Children'),'EdgeColor','r')
end
end
if SN( 11.3 < SG & SG < 16 )
for SNM = SN_Mediocre ( 1 : length (SN_Mediocre) )
set(get(f3(SNM),'Children'),'EdgeColor','y')
end
end
if SN( SG >= 16 )
for SNT = SN_Top ( 1 : length (SN_Top) )
set(get(f3(SNT),'Children'),'EdgeColor','g')
end
end
如何解决此错误?提前谢谢。
答案 0 :(得分:0)
您是否尝试过抓住酒吧的补丁手柄?
您可能必须将所有条形图绘制为单独的条形图。 这样的事情可能有用:
figure
hold on
for n = 1:10
bh(n) = bar(n,n);
end
set(get(bh(1),'Children'),'EdgeColor','r','FaceColor','w')
答案 1 :(得分:0)
试试这个:
SN= [1:14]';
SG= [15.5; 13; 15; 12.2; 13.6; 13.4; 14.2; 9; 17.7; 15; 12.5; 10; 16; 13.6];
SN_UnderDogs= [8; 12];
SN_Mediocre= [1; 2; 3; 4; 5; 6; 7; 10; 11; 14];
SN_Top= [9; 13];
for cc = 1:length(SN)
f3(cc) = bar(cc, SG(cc), 'FaceColor', 'white');
hold on;
end
if SN( SG <= 11.3 )
for SNUD = SN_UnderDogs ( 1 : length (SN_UnderDogs) )
% set(get(f3(SNUD),'Children'),'EdgeColor','r')
cellfun(@(x) set(x,'EdgeColor','r'), get(f3(SNUD),'Children'))
end
end
if SN( 11.3 < SG & SG < 16 )
for SNM = SN_Mediocre ( 1 : length (SN_Mediocre) )
% set(get(f3(SNM),'Children'),'EdgeColor','y')
cellfun(@(x) set(x,'EdgeColor','y'), get(f3(SNM),'Children'))
end
end
if SN( SG >= 16 )
for SNT = SN_Top ( 1 : length (SN_Top) )
% set(get(f3(SNT),'Children'),'EdgeColor','g')
cellfun(@(x) set(x,'EdgeColor','g'), get(f3(SNT),'Children'))
end
end