How do I scale the height of bars output from a histogram?
조회 수: 30 (최근 30일)
이전 댓글 표시
I have data output from a simulation that wherin I wish to plot a histogram of the values generated. The experimental data that I'm trying to model is the summation of individual probability densities, each of which is weighted by a scalar. I'd like to be able to scale the height of the histograms, but I can't see how to do that since there is no actual y data contained in it like there is for a simple plot. I can't just go histObj.Ydata, so how can access the bin counts and scale them?
댓글 수: 0
채택된 답변
Shubham
2023년 2월 9일
Hi Andrew,
If you have data output from a simulation that you want to plot as a histogram, you can use the histogram function in MATLAB. The function will automatically generate the bin counts for you. If you want to scale the height of the histogram, you can simply multiply the bin counts by the desired scalar.
Here's an example:
data = your_simulation_data; % replace this with your own data
scalar = your_scalar; % replace this with your desired scalar
bin_edges = linspace(min(data), max(data), 100); % define bin edges
bin_counts = histcounts(data, bin_edges); % calculate bin counts
bin_counts_scaled = bin_counts * scalar; % scale the bin counts
bar(bin_edges(1:end-1), bin_counts_scaled, 'hist'); % plot the histogram
This code will create a histogram of the data with 100 bins, calculate the bin counts, scale the bin counts by scalar, and plot the resulting histogram using the bar function.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!