To find histogram of two variables

6 views (last 30 days)
Hi,
I need to find Histogram properties of two variable x and y and to store it in a separate cell array a. I have used below code but, I am getting only the histogram properties of y, Kindly help me with this. Thanks in advance.
x = rand(1000,1);
y = rand(1500,1);
a = histogram(x);
b = histogram(y);
c = {a;b};

Accepted Answer

KSSV
KSSV on 13 Jul 2022
x = rand(1000,1);
y = rand(1500,1);
[N{1},edges{1}] = histcounts(x);
[N{2},edges{2}] = histcounts(y);
  1 Comment
KSSV
KSSV on 13 Jul 2022
x = rand(1000,1);
y = rand(1500,1);
figure(1)
h(1) = histogram(x);
figure(2)
h(2) = histogram(y);
h(1)
ans =
Histogram with properties: Data: [1000×1 double] Values: [97 93 90 107 118 86 113 103 91 102] NumBins: 10 BinEdges: [0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1] BinWidth: 0.1000 BinLimits: [0 1] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties
h(2)
ans =
Histogram with properties: Data: [1500×1 double] Values: [154 167 150 139 161 157 116 163 140 153] NumBins: 10 BinEdges: [0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1] BinWidth: 0.1000 BinLimits: [0 1] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!