How do I scale the height of bars output from a histogram?
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andrew Morris
el 9 de Feb. de 2023
Comentada: Andrew Morris
el 10 de Feb. de 2023
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 comentarios
Respuesta aceptada
Shubham
el 9 de Feb. de 2023
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!