Matlab : Combined histograms

51 views Asked by At

I try to combine with a "hold on" several histograms that I get from several figures. The figures have the same X axis that I defined. Nevertheless I can't display. Would you have a solution?

close all;
clearvars;

xlimArr = [0 0.05];

dataset = xlsread('DEHS_REF.xlsx', 'Feuil1', 'A2:B47');

h0=hgload('Données_LOAC_n°0_DEHS_1');
h1=hgload('Données_LOAC_n°1_DEHS_1');
h2=hgload('Données_LOAC_n°2_DEHS_1');
h3=hgload('Données_LOAC_n°3_DEHS_1');

g0 = findobj(h0, 'type', 'Histogram');
g1 = findobj(h0, 'type', 'Histogram');
g2 = findobj(h0, 'type', 'Histogram');
g3 = findobj(h0, 'type', 'Histogram');

hist_chanel_1  = g0(2);
hist_chanel_2  = g1(2);
hist_chanel_3  = g2(2);
hist_chanel_4  = g3(2);

figure();

histogram(hist_chanel_1.Data, 'BinWidth', hist_chanel_1.BinWidth);
hold on 
histogram(hist_chanel_2.Data, 'BinWidth', hist_chanel_2.BinWidth);
histogram(hist_chanel_3.Data, 'BinWidth', hist_chanel_3.BinWidth);
histogram(hist_chanel_4.Data, 'BinWidth', hist_chanel_4.BinWidth);
hold off

xlabel('Value [V]');
ylabel('Nb of peak');
title('AerosolsGenerator peak distribution (amplitude)');
xlim(xlimArr); ```
1

There are 1 answers

0
Paul On

I am coming back to you having found the answer partially. I don't know why but taking the sorted data from a histogram doesn't allow to superimpose them. By taking directly the variables of the workspace allows to remake the histograms and to overlay them

% ANALYSE DEHS MEASURE LOAC V2
% Paul Miailhe - jannuary 2022
% Last modification: jannuary 2022 by Paul Miailhe.

%% Load variable 

close all;
clearvars;

xlimArr = [0 0.05];

channel1_LOAC0 = load('chanel1_LOAC_n°0.mat');
channel1_LOAC1 = load('chanel1_LOAC_n°1.mat');
channel1_LOAC2 = load('chanel1_LOAC_n°2.mat');
channel1_LOAC3 = load('chanel1_LOAC_n°3.mat');

channel2_LOAC0 = load('chanel2_LOAC_n°0.mat');
channel2_LOAC1 = load('chanel2_LOAC_n°1.mat');
channel2_LOAC2 = load('chanel2_LOAC_n°2.mat');
channel2_LOAC3 = load('chanel2_LOAC_n°3.mat');


%% Graphique : 
    %Channel 1
    
h(1) = figure;

subplot(2,1,1);

histogram(channel1_LOAC0.data_channel1, channel1_LOAC0.bins)

hold on 
histogram(channel1_LOAC1.data_channel1, channel1_LOAC1.bins)
histogram(channel1_LOAC2.data_channel1, channel1_LOAC2.bins)
histogram(channel1_LOAC3.data_channel1, channel1_LOAC3.bins)

hold off
xlabel('Value [V]');
ylabel('Nb of peak');
title('CH1 result distribution (amplitude)');
legend('show');
xlim(xlimArr);

    %Channel 2

subplot(2,1,2);

histogram(channel2_LOAC0.data_channel2, channel2_LOAC0.bins)

hold on 
histogram(channel2_LOAC1.data_channel2, channel2_LOAC1.bins)
histogram(channel2_LOAC2.data_channel2, channel2_LOAC2.bins)
histogram(channel2_LOAC3.data_channel2, channel2_LOAC3.bins)

hold off
xlabel('Value [V]');
ylabel('Nb of peak');
title('CH2 result distribution (amplitude)');
legend('show');
xlim(xlimArr);