问题
In my plot, I'm trying to display the average delay time from 6 airports for each of the 5 dates.
Here is the code I have so far:
F = dataset('xlsfile','Lab2_Delta');
DATES = {'11/26/2013','11/27/2013','11/28/20113','11/29/2013','11/30/2013'};
ORIGINS = {'CVG','ORD','ATL','LAX','MIA','DFW'};
for Index = 1:6
for Index2 = 1:5
Origin_Index = find(strcmp(F.Origin,ORIGINS(Index)));
Date_Index = find(strcmp(F.Date,DATES(Index2)));
Temps(Index2,Index) = mean(F.Delay(Date_Index));
end
end
bar(1:5,Temps(:,Index)); hold on;
legend('CVG','ORD','ATL','LAX','MIA','DFW');
set(gca,'XTick',1:length(DATES));
set(gca,'XTickLabel',DATES);
ylabel('Mean Delay Times'); title('Delay Times Around Thanksgiving');
The plot that is displayed only shows the bars for one airport (CVG). How do I go about displaying the other cities?
回答1:
If you can construct a matrix Y
with a row for each date, and a column for each airport, then bar(1:5,Y)
should do the trick.
dates=1:5
delayCVG=rand(1,5);
delayMIA=rand(1,5)+1;
delayATL=rand(1,5)+2;
delayLAX=rand(1,5)+3;
delayDFW=rand(1,5)+4;
delayORD=rand(1,5)+5;
delay=[delayCVG' delayMIA' delayATL' delayLAX' delayDFW' delayORD'];
bar(dates,delay)
来源:https://stackoverflow.com/questions/23878020/matlab-graphing-multiple-vertical-bar-plots