目标是绘制以下的柱状图:
代码:
state_x=[hunx;suix;kongx]';
xx=[6,8,10,12,14,16];
figure
bar(xx,state_x);
for i=1:length(hunx)
text(xx(i)-0.5,state_x(i,1),num2str(state_x(i,1)),'HorizontalAlignment','center','VerticalAlignment','bottom');
text(xx(i),state_x(i,2),num2str(state_x(i,2)),'HorizontalAlignment','center','VerticalAlignment','bottom');
text(xx(i)+0.5,state_x(i,3),num2str(state_x(i,3)),'HorizontalAlignment','center','VerticalAlignment','bottom');
end
xticklabels({'6','8','10','12','14','16'});
ylim([0,900]);
set(gca,'fontsize',13);
xlabel('转速(rpm)','FontSize',15); ylabel('频率(Hz)','FontSize',15);
其中:state_x的数据为6*3矩阵
解释下循环中的程序:text(xx(i)-0.5,state_x(i,1),num2str(state_x(i,1)),'HorizontalAlignment','center','VerticalAlignment','bottom');
% xx(i)-0.5,state_x(i,1)表示为所要标注的位置,一个为横轴上的,一个为纵轴上的;文章来源:https://www.toymoban.com/news/detail-560940.html
% num2str(state_x(i,1))表示所要标注的数值;文章来源地址https://www.toymoban.com/news/detail-560940.html
到了这里,关于matlab柱状图的绘制及数值的标注的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!