How to change the ylim for all histogram figures after a for loop?

25 ビュー (過去 30 日間)
Sharif Khalil
Sharif Khalil 2019 年 10 月 9 日
コメント済み: Star Strider 2019 年 10 月 9 日
Hi,
I have 12 histograms, and each of them has different maximum number of counts, I want the ylim of all figures to be unified, i.e. ylim to be highest value of counts for all 12 histograms. That is represented in MaxH in the code below:
Max = ceil(max(totalPowerdB(:)))+1;
SS = unique(sort(totalPowerdB(:)));
Min = floor(SS(2))-1;
nbins = 20;
count = 0;
MaxH = 0;
for jj = 1:iRegion
for ii = 1:1
count = count+1;
if totalPowerdB(jj,:,ii)~=-inf
figure(count)
end
txt = ['Region ',num2str(jj),' Reciever ',num2str(ii)];
H = histogram(totalPowerdB(jj,:,ii),nbins,'FaceColor',rand(1,3));
if max(H.Values) > MaxH
MaxH = max(H.Values);
end
hold on; grid on;
legend(txt);
title('Received Power Histogram')
xlim([Min Max]);
xlabel('Power Level [dB]');
ylabel('Counts');
end
end

採用された回答

Star Strider
Star Strider 2019 年 10 月 9 日
I can’t run your code (no data), so I simulated it.
This seems to work:
for k = 1:12
figure(k)
H = histogram(rand(20), 20, 'FaceColor',rand(1,3));
HAx{k} = H.Parent; % Get & Save Axes Handles
maxH(k) = max(H.Values);
end
ylim([HAx{:}], [0 max(maxH)])
  2 件のコメント
Sharif Khalil
Sharif Khalil 2019 年 10 月 9 日
Thanks, it works, sorry the data is 12X125X1216, so I could not post it with the question.
Star Strider
Star Strider 2019 年 10 月 9 日
As always, my pleasure!
No worries — I felt it necessary to explain the reason for my simulation.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by