フィルターのクリア

Normalizing histfit plots to all have the same height of 1

19 ビュー (過去 30 日間)
Brett Ruben
Brett Ruben 2020 年 10 月 11 日
コメント済み: Matthew ODonohue 2022 年 2 月 28 日
Hello,
I have below my code that successfully just plots the fits without the histograms, thanks to another answered question on here. As you can see I am plotting multiple fits onto the same figure, but I want them all to have the same height of ,1 but can't seem to find a direct way to do that from here. Please let me know if you have a solution! I can imagine it isn't that difficult, but I am still learning MATLAB. Thank you!
figure(1)
h70 = histfit(x70, 10000);
set(h70(2), 'color', 'm')
delete(h70(1))
hold on
h90 = histfit(x90, 10000);
set(h90(2), 'color', 'y')
delete(h90(1))
hold on
.
.
.
  1 件のコメント
Brett Ruben
Brett Ruben 2020 年 10 月 11 日
I have also tried an answer by Star Strider, here is the code and here is the figure it generates. Looks like the Y-axis certainly has changed, but the plots are not peaking at 1.
figure(1)
h70 = histfit(x70, 10000);
set(h70(2), 'color', 'm')
delete(h70(1))
yt70 = get(gca, 'YTick');
set(gca, 'YTick', yt70, 'YTickLabel', yt70/numel(x70))
hold on
h90 = histfit(x90, 10000);
set(h90(2), 'color', 'y')
delete(h90(1))
yt90 = get(gca, 'YTick');
set(gca, 'YTick', yt90, 'YTickLabel', yt90/numel(x90))
hold on
.
.
.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2020 年 10 月 11 日
In a Comment in Getting FWHM from distribution fitter you requested my attention to this.
Try this:
a = randn(1,1E+4); % Create Data
b = randn(1,1E+4)*2; % Create Data
figure
ha = histfit(a,1000);
set(ha(2), 'color','m')
yd = ha(2).YData;
ha(2).YData = ha(2).YData/max(ha(2).YData);
delete(ha(1))
hold on
hb = histfit(b,1000);
set(hb(2), 'color','y')
hb(2).YData = hb(2).YData/max(hb(2).YData);
delete(hb(1))
hold off
.
  3 件のコメント
Star Strider
Star Strider 2020 年 10 月 12 日
I very much appreciate your compliment!
As always, my pleasure!
Matthew ODonohue
Matthew ODonohue 2022 年 2 月 28 日
Star Strider,
Awesome solution. Thank you so much, seriously. However, what was your motive for defining the variable "yd"? And what is it?
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by