how to plot percentage on y axis

3 views (last 30 days)
suchismita
suchismita on 15 May 2011
sir,i want to plot a variable 'L 'which is for life time of mobile nodes.i am getting the 'L' result numerically but its not showing on the graph.i want to plot it in both normal graph form and histogram form.i need the graph in percentage form i mean the y-axis should show the result in percentage and x-axis must show a fixed time .that means i m not taking any variable for expressing time.i found some expression from internet like below.but i m not getting exactly how to write the proper command.
hist(L); h=gca; labels=get(h,'yticklabel'); % get the y axis labels labels_modif=[num2str(100*str2num(labels)) ones(length(labels),1)*'%'] set(h,'yticklabel',labels_modif);
its only showing the y-axis labeling as percentage but not the exact result. pllzz help me sir.its urgent. Expecting a favorable reply. Thanking u SUCHI.

Answers (1)

Oleg Komarov
Oleg Komarov on 15 May 2011
Here's an example of how to set % values for the Y axis:ù
% Example input
L = 0:.1:1;
% Plot
plot(1:numel(L),L);
% Create labels
labels = reshape(sprintf('%5.1f%%',L*100),6,[]).';
% Adjust labels on plot
set(gca,'yticklabel',labels)
  2 Comments
suchismita
suchismita on 16 May 2011
hello sir,thanx for ur suggestion.but i am suffering from the same problem.its only showing the y axis labeling in percentage but not the result in percentage.i am attaching the last portion of my code below.
for j=1:k
for i=1:N+M
ltj=cumsum(lij*xij);
L=max(cumsum(ltj));
end
end
ylabel('lifetime');
title('L');hold on;grid on;hist(L);
i want to represent the result of 'L' above in percentage form where time is fixed.i want it 1st in histogram form and again in normal graph.pllzzz help me.
regards SUCHI
Oleg Komarov
Oleg Komarov on 16 May 2011
Well, if you don't give me example inputs for k, N, M, lij and xij my cristal ball surely won't help.
To get percentages from a number say maxA = 10 drawn from an array A = [10 2 5 6];
L = maxA/sum(A)*100;

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!