Clear Filters
Clear Filters

How to sum different histograms in just one?

2 views (last 30 days)
I have tried with the bars because I could not do it with the histogram. How can I do the same with the histogram function?
clc
clear all
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr=25 years %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
File50=dir('C:\Users\Daniela\OneDrive - Politecnico di Milano\THESIS\Data process\Statistics\Harzard\Ourthe\tr_25');
for k=3:length(File50)
FileNames25=File50(k).name;
end
i25=0;
N_new25=0;
a=0.001;
b=5;
h=0.1;
for k=3:length(File50)
i=i+1;
m_i25=File50(3).name;
A_i25=imread(m_i25);
image(A_i25);
max_depth25=max(A_i25,[],'all');
min_depth25=min(A_i25 (A_i25>0));
I_i25=find(A_i25>0.001);
x=[a:h:b];
y=[a:h:b-0.1];
[N_i]=histcounts(A_i25,x);
N_old25=N_new25;
N_new25=N_old25+N_i;
end
area_25=sum(N_new25)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr=50 years %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
File50=dir('C:\Users\Daniela\OneDrive - Politecnico di Milano\THESIS\Data process\Statistics\Harzard\Ourthe\tr_50');
for k=1:length(File50)
FileNames50=File50(k).name;
end
i=0;
N_new50=0;
for k=1:length(File50)
i=i+1;
m_i50=File50(3).name;
A_i50=imread(m_i50);
image(A_i50);
max_depth50=max(A_i50,[],'all');
min_depth50=min(A_i50 (A_i50>0));
I_i50=find(A_i50>0.001);
x=[a:h:b];
y=[a:h:b-0.1];
[N_i]=histcounts(A_i50,x);
N_old50=N_new50;
N_new50=N_old50+N_i;
end
area_50=sum(N_new50)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr=100 years %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
File100=dir('C:\Users\Daniela\OneDrive - Politecnico di Milano\THESIS\Data process\Statistics\Harzard\Ourthe\tr_100');
for k=1:length(File100)
FileNames100=File100(k).name;
end
i=0;
N_new100=0;
for k=1:length(File100)
i=i+1;
m_i100=File100(3).name;
A_i100=imread(m_i100);
image(A_i100);
max_depth100=max(A_i100,[],'all');
min_depth100=min(A_i100 (A_i100>0));
I_i100=find(A_i100>0.001);
x=[a:h:b];
y=[a:h:b-0.1];
[N_i]=histcounts(A_i100,x);
N_old100=N_new100;
N_new100=N_old100+N_i;
end
area_100=sum(N_new100)
figure (1)
bar(y,N_new100,'FaceAlpha',0.5,'FaceColor','y')
hold on
bar(y,N_new50,'FaceAlpha',0.5,'FaceColor',[1, 0.5, 0])
hold on
bar(y,N_new25,'FaceAlpha',0.5,'FaceColor','r')
title('Flooded area water depth - River Ourthe)');
xlabel('Water depth')
legend('tr=100 years','tr=50 years','tr=25 years')

Answers (0)

Community Treasure Hunt

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

Start Hunting!