display every value of a matrix in histogram
14 views (last 30 days)
Show older comments
Hi all, i need some help with this because i am stucked.
I have a matrix named val which contains180 values (numbers from -90:89) and i wan to put every value on histogram, the code is the below:
%try to find the maimum value on the array to create the xx' axis
rangeTheta=max(abs([lines.theta]));
%ceil to the closest hundred
ceilRangeTheta=100*ceil(rangeTheta/100);
%try to find the maimum value on the array to create the xx' axis
rangeMaxHough=max(val);
%ceil to the closest hundred
ceilRangeMaxHough=100*ceil(rangeMaxHough/100);
figure;title('hough max');hold on;
nbins2=-90:89;
h2=histogram(val,nbins2);
ylim([0, ceilRangeMaxHough]);
set(gca,'YTick',0:100:ceilRangeMaxHough)
xlim([-ceilRangeTheta, ceilRangeTheta]);
set(gca,'XTick',-rangeTheta:10:rangeTheta)
The proble is that histogram counts the numbers between spaces like around 60 number have value between 150-200 etc.
i want o create a histogram like this, where every row of my array will be displayed on every x bin, and on y axis will be displayed the value of the row, how can i do this?
0 Comments
Accepted Answer
dpb
on 29 Jul 2019
Edited: dpb
on 29 Jul 2019
Ah! The question isn't about a histogram at all...or, it is, but not a histogram of the data but just plot the counts computed elsewhere. That wasn't clear to me before, certainly.
Steven's solution, or
val=val.'; val=val(:); % orient as vector in row-major order as example shows want...
bins=[-90:89];
bar(bins,val)
NB: If val is stored as you pasted it in as 2D array, you'll have to get it ordered in memory correctly first to plot in the sequence as you show. ML storage order is column-major so as is, would go down columns first, not across rows...
More Answers (2)
dpb
on 28 Jul 2019
hist(val,unique(val))
7 Comments
dpb
on 29 Jul 2019
" the amount of the value that every row have."
I have no idea what the above means.
Attach the data and try again to explain what you think you want.
hist counts the number of elements in a bin..if you're trying to plot something else against a bin, then that will need bar with whatever that something else is...
Steven Lord
on 29 Jul 2019
Does the data represent the counts for each of the bins? If so call histogram and specify the BinEdges and BinCounts name/value pairs. See the description of the counts input argument on the histogram documentation page.
0 Comments
See Also
Categories
Find more on Annotations 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!