How do I scale the height of bars output from a histogram?

29 次查看(过去 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?

采纳的回答

Shubham
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 CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by