日度归档:2023年4月6日

Vehicle Fuel Efficiency

dat = datastore(“fuelEconomy2.txt”); %载入数据

dat.ReadSize = 362; %提取前362数据

data = dat.read; %读取数据

[gNum,gVal] = findgroups(data.NumCyl); %获取 NumCyl 数据及ID

avgMPG = splitapply(@mean,data.CombinedMPG,gNum);

b = bar(avgMPG); % bar图

xlabel(“Number of cylinders”) %

title(“Average MPG”)

f = gcf; % 图

a = gca; %轴

f.Color = [0.81 0.87 0.9]; %图颜色

a.Color = [0.81 0.87 0.9]; %轴颜色

a.Box = “off”; % 图框不显示

a.YAxisLocation = “right”;

a.YGrid = “on”;

a.GridColor = [1 1 1];

a.GridAlpha = 1;

a.XTickLabel = gVal;

a.YLim = [0 40];

ax = a.XAxis;

ax.TickDirection = “out”;

b.FaceColor = [0,0.31,0.42];

b.BarWidth = 0.5;