paradox : updateing 'Data' property for histogram()
2 views (last 30 days)
Show older comments
I am trying to set the 'Data' property of a histogram once I plot it as follows:
figure(10);
h = histogram(4+randn(1000,1)); % plot histogram for first time for data~N(4,1)
h.Data = randn(1000,1); % update plot with new data ~ N(0,1)
The above approach updates the data, however does not change other related properties, as a result only a part of the samples are shown.
Any ideas how to update the histogram without having to plot it from scratch?
Cheers, M
4 Comments
Answers (2)
Steven Lord
on 5 Aug 2016
- The Data property contains the actual data used to generate the histogram. You explicitly changed this, so it's not surprising that it is different.
- The Values property is dependent on the Data and the locations of the bins, so it's not surprising that it is different. [As an extreme example, if I binned points based on their distance from Boston, Massachusetts in bins of 0-10, 10-20, 20-30, and 30-40 miles from Boston, I'd get VERY different results if I specified points in Massachusetts than if I specified points in California for those same bins.]
- The Parent property is based on the axes that contains the histogram. The two histograms are in different subplot axes, so it's not surprising that it is different.
- The Annotation property is a handle object, and the meaning of == for handle objects is slightly more restrictive than == for non-handle objects. Instead of asking "do each of your properties have the same values?" == for handles asks "do you refer to the same object?" The two histogram objects don't share the same object for their Annotation properties, so == returns false. But if you call isequal on the two handle objects from the Annotation properties (which asks the "do each of your properties have the same values?" question) you'll find that they are equal.
Based on your picture, I think I see what you want to do. You want the histogram object to recompute the bins based on the extent of the new data, right? If you change the BinMethod property of the second histogram to 'auto' (even though the value is already 'auto') "touching" that property will trigger the histogram object to recalculate its bin edges.
1 Comment
Guillaume
on 5 Aug 2016
Sounds like a Recalculate method would be a useful addition to the Histogram class, then.
More obvious than trying to find which property would trigger a recalculation.
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!