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.
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
채택된 답변
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!