display every value of a matrix in histogram
14 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231655/image.png)
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231656/image.png)
0 个评论
采纳的回答
dpb
2019-7-29
编辑:dpb
2019-7-29
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...
更多回答(2 个)
dpb
2019-7-28
hist(val,unique(val))
7 个评论
dpb
2019-7-29
" 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
2019-7-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!