display every value of a matrix in histogram

조회 수: 17 (최근 30일)
pasta pontikaki
pasta pontikaki 2019년 7월 28일
편집: pasta pontikaki 2019년 7월 29일
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?

채택된 답변

dpb
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...
  댓글 수: 1
pasta pontikaki
pasta pontikaki 2019년 7월 29일
편집: pasta pontikaki 2019년 7월 29일
the previous code worked thank you very much. The array is not 2D is a 1D vector but i cited as a 2D for convinience.
The result is this tank you very much.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

dpb
dpb 2019년 7월 28일
hist(val,unique(val))
  댓글 수: 7
dpb
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...
pasta pontikaki
pasta pontikaki 2019년 7월 29일
편집: pasta pontikaki 2019년 7월 29일
val is a matrix with the below 180 number , so i want o create a histogram with with x-axis vary from -90:89. So every value of the matrix is related to a specific bin in x-axis.
For example the first value is represented with the bin -90 so the value in yy' is 263, the second value is bin -89 so i want to reach until 245 etc
PS I really appreciate your help dude
val=[ 263 245 246 240 229 238 241 244 247 246 251 239 256 242 246 267 268 268
287 297 266 261 270 299 337 286 282 332 417 578 458 320 334 374 319 323
344 351 359 324 356 362 327 282 286 258 244 233 215 210 202 213 199 212
196 200 192 196 194 183 182 183 185 184 191 195 178 177 184 174 179 175
166 171 174 166 169 155 157 161 169 161 163 156 154 153 157 157 154 152
150 156 156 152 153 163 161 161 164 152 155 160 158 158 158 164 161 160
163 167 170 177 187 203 200 209 218 230 275 280 350 429 428 379 421 331
313 371 384 397 393 374 397 422 386 388 392 301 261 255 252 240 241 244
259 254 243 243 242 252 247 252 247 243 254 245 237 234 236 235 241 244
243 242 237 237 234 225 235 231 236 234 229 231 234 243 246 237 232 237]

댓글을 달려면 로그인하십시오.


Steven Lord
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.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by