how to plot percentage on y axis
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Oleg Komarov
2011-5-15
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 个评论
Oleg Komarov
2011-5-16
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;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!