# Receive Error using / Arguments must be numeric, char, or logical when I am using histogram

2 views (last 30 days)
Ceren yüksel on 18 Dec 2021
Commented: Ceren yüksel on 20 Dec 2021
I am working on dicom file. I Get Error using / Arguments must be numeric, char, or logical error when histogram lines are working. Help me please
(h1 = histogram(a, 64)/n;
h2 = histogram(b,64)/n;)
a = double(Org);
b = double(Ref);
%a = Org(:);
%b = Ref(:);
n = length(a);
H = zeros(25600,25600);
for i = 1:n
x = a(i);
y = b(i);
H(x+1,y+1) = H(x+1,y+1) + 1 ;
end
h1 = histogram(a, 64)/n;
h2 = histogram(b,64)/n;
s = zeros(32768,32768);
H = H/n;
for i = 1: 64
for j = 1:128
if H(i,j) == 0 || h1(i) == 0 || h2(j) == 0
s(i,j) = 0;
else
s(i,j)= H(i,j)*log2(H(i,j)/(h1(i)*h2(j)));
end
end
end

Dave B on 18 Dec 2021
Edited: Dave B on 18 Dec 2021
histogram returns a graphics object, so when you try to divide that by n you'll get an error.
If you're looking for the values in the histogram, try the histcounts function:
n=5;
histcounts(rand(100,1))/n
ans = 1×5
3.0000 5.0000 4.6000 3.8000 3.6000
If you want to deivide the values before making the histogram, just slip the /n into the parentheses:
histogram(rand(100,1)/n)
Ceren yüksel on 20 Dec 2021
many thanks it works

### Categories

Find more on DICOM Format in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by