How can I have for loop show me each histogram it created rather then play it like a movie?
19 ビュー (過去 30 日間)
古いコメントを表示
I am trying to see each histogram (with a pdf fit to it) for each value within the for loop but when i run it it is "playing" each histogram plot back to back like a short movie. I want to see each histogram and potentailly place it all in one figure if that makes sense. Here is the current code I have for the section.
"
for i=1:10;
idx_age = find(age >= (i-1)*1000 & age < i*1000);
age_tmp = age(idx_age);
iso_tmp = d18O (idx_age);
x1 = iso_tmp
% fit normal distribution to sample data
pd1 = fitdist(x1,'Normal')
mu1 = mean(pd)
sigma1 = std(pd)
% Overlay a plot of the fitted pdf.
x1_pdf = [-50:0.1:-20]
y1 = pdf(pd,x1_pdf)
% then use iso_tmp to make a pdf within for loop and save to a matrix to plot
figure (3)
histogram(x1,'Normalization','pdf')
line(x1_pdf,y1)
"
0 件のコメント
採用された回答
Star Strider
2022 年 9 月 13 日
I am not certain what you are doing or the result you want. I don’t see an end for the for loop, so I assume everything is in the same loop.
figure(3)
for i=1:10;
idx_age = find(age >= (i-1)*1000 & age < i*1000);
age_tmp = age(idx_age);
iso_tmp = d18O (idx_age);
x1 = iso_tmp
% fit normal distribution to sample data
pd1 = fitdist(x1,'Normal')
mu1 = mean(pd)
sigma1 = std(pd)
% Overlay a plot of the fitted pdf.
x1_pdf = [-50:0.1:-20]
y1 = pdf(pd,x1_pdf)
% then use iso_tmp to make a pdf within for loop and save to a matrix to plot
subplot(5,2,i)
histogram(x1,'Normalization','pdf')
line(x1_pdf,y1)
title(sprintf('Histogram %2d',i))
end
.
14 件のコメント
Star Strider
2022 年 9 月 14 日
No worries! (I was off doing other things for a while.)
Plotting histograms and pdf’s together in one axes would likely not be possible without hopelessly confusing all of them. For that reason,.I would put the 10 plots together in one figure either using subplot (similar to what I posted earlier) or tiledlayout. Considering that they all share the same independent variable, stackedplot might also be an option. With all of these, I would use the same axis call (as I outlined earlier) to make differences between them readily apparent, instead of using automatic axis scaling that would obscure the differences.
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!