How could you write a function that returns a histogram with axis labels and title
1 view (last 30 days)
Show older comments
Currently I have: which creates the graph with the axis and title labels but the data for the histogram doesn't show up on the histogram. pls help <3
function [a,b,c,d]= Histogram_Function(x)
a= hist(x);
b= title('asdasd');
c= xlabel('ban');
d=ylabel('anana');
end
0 Comments
Answers (1)
dpb
on 4 Oct 2018
hist when save the return value only returns the counts vector and, as you've discovered; doesn't actually draw the plot.
To continue to use hist you would have to do something like
function [cnts,cntrs,hLabels]= Histogram_Function(x)
[cnts,cntrs]=hist(x);
bar(cntrs,cnts)
hLabels(1)=title('asdasd');
hLabels(2)=xlabel('ban');
hLabels(3)=ylabel('anana');
end
NB1: USE MEANINGFUL VARIABLE NAMES!!! Makes very difficult to read and maintain code when there's no semblance of any relationship between the variable name and its purpose.
NB2: hist has been deprecated; strongly urge to consider using histogram instead unless you are forced to use a release prior to R2014b.
...
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!