figure; bar( xdata, ydata, 'stacked' );
boxPatchXY = cell( numGroups, numItems );
minX = 0.6 : 1 : numItems + 0.6;
maxX = 1.4 : 1 : numItems + 1.4;
midY = NaN( numGroups, 1 );
groupData = ydata( group, : );
maxY = max( groupData ) + minY;
midY( group ) = ( minY + maxY ) / 2 ;
itemX = vertcat( startX, startX, endX, endX, endX, startX );
itemY = vertcat( midY( group ), midY( group ) - groupData( item ) / 2,...
midY( group ) - groupData( item ) / 2, midY( group ),...
midY( group ) + groupData( item ) / 2, midY( group ) + groupData( item ) / 2 );
boxPatchXY{ group, item } = horzcat( itemX, itemY );
boxPatchPlots = gobjects( numel( boxPatchXY ), 1 );
for idx = 1:numel( boxPatchPlots )
boxPatchPlots( idx ) = patch( boxPatchXY{ idx }( :, 1 ), boxPatchXY{ idx }( :, 2 ),...
'FaceColor', barColors{ idx }, 'EdgeColor', barColors{ idx },...
'Parent', aLaneColumns );