Histogram - problem with X axis (shifting the data)
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Karolina
am 9 Jan. 2016
Beantwortet: Guillaume
am 11 Jan. 2016
I plotted a histogram which represent three data: A, B, C. The A represent the sum of B+C. I think there is something wrong with X axis (they are shifted for every data), because the C data for some values is higher than A. Does anyone know what can be wrong in my code?
% Generate histogram
h0=histogram(C,'BinLimits',[0.00,3.00],'FaceColor',[0.8 0.8 0.8],'EdgeColor','none','FaceAlpha',1);
hold on
h1=histogram(A,'BinLimits',[0.00,3.00],'FaceColor',[0 0 0],'EdgeColor','none','FaceAlpha',1);
hold on
h2=histogram(B,'BinLimits',[0.00,3.00],'FaceColor',[0.3 0.3 0.3],'EdgeColor','none','FaceAlpha',0.7);
hold on
xlim([0.1,1.4]);
2 Kommentare
Image Analyst
am 9 Jan. 2016
What is your C data? Is it the counts you're talking about, or the bin edges?
Or is it the actual C, which you say is equal to A+B. If B is negative then C could be less than A for a particular element.
Akzeptierte Antwort
Guillaume
am 11 Jan. 2016
My guess is that since you leave histogram to choose its own bins, your histograms don't have exactly the same bins. You can check the bins with:
h0.BinEdges %it would make more sense to call h0: hC
h1.BinEdges %it would make more sense to call h1: hA
h2.BinEdges %it would make a lot more sense to call h2: hB
If that is indeed the problem, either fix the bins to start with, or reuse the bins of the first histogram in the seconds and thid:
hC = histogram(C, 'BinLimits',[0.00,3.00],'FaceColor',[0.8 0.8 0.8],'EdgeColor','none','FaceAlpha',1);
hold on
hA = histogram(A, hc.BinEdges, 'BinLimits',[0.00,3.00],'FaceColor',[0 0 0],'EdgeColor','none','FaceAlpha',1);
hB = histogram(B, hc.BinEdges, 'BinLimits',[0.00,3.00],'FaceColor',[0.3 0.3 0.3],'EdgeColor','none','FaceAlpha',0.7);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!