MATLAB: How to display a value on bar plottingtext; How can I display the value at the top of each bar? assume that I have the following bar plot: Best Answer Try this (if you have R2014b or later):y1 = [2 2 3; 2 5 6; 2 8 9; 2 11 12];hBar = bar(y1,1); % Return ‘bar’ Handlefor k1 = 1:size(y1,2) ctr(k1,:) = bsxfun(@plus, hBar(1).XData, hBar(k1).XOffset'); % Note: ‘XOffset’ Is An Undocumented Feature, This Selects The ‘bar’ Centres ydt(k1,:) = hBar(k1).YData; % Individual Bar Heights text(ctr(k1,:), ydt(k1,:), sprintfc('%.1f', ydt(k1,:)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom', 'FontSize',8, 'Color','b')endthe sprintfc function is undocumented. It is essentially the same as sprintf, and augmented to produce a cell array of outputs. This makes it very efficient in situations such as this, where the result is a cell array. Related SolutionsMATLAB: Add text above grouped bars '%%' is the escape sequence for percentage symbol as shown here.sprintfc('%.1f %%', ydt(k1,:)) MATLAB: How to define an arbitrary constant for equations If you are talking about making an assumption, you can do it as follows:v1=6;v3=18;syms v2 v4 v5 v6eqn1= -v4+v5==-v3;eqn2= -v2+v6==v3;eqn3= -v5-v6==-v1;assume(v6~=0)[v2 v4 v5 v6]=solve(eqn1, eqn2, eqn3);[v2 v4 v5 v6] Related QuestionShow numbers with Grouped BarsBar graph comparison with custom x-axis and textHow to change color bar? how to keep initial abscisses valuesHow to change the colours of a bar chart
Best Answer