What should I do?-Array indices must be positive integers or logical values.

1 次查看(过去 30 天)
My code
clc
clear
close all
a=imread('Screenshot_20210628.jpg');
g =rgb2gray(a);
arr=zeros(1,256);
[x,y,z]=size(g);
for i=1:x
for j=1:y
m=g(i,j);
arr(m)=arr(m)+1;
end
end
stem(arr);
Array indices must be positive integers or logical values.
Error in line 11
arr(m)=arr(m)+1;

采纳的回答

Wan Ji
Wan Ji 2021-8-26
Hi,
g(i,j) may be zero, then m becomes zero. change it like this
clc
clear
close all
a=imread('Screenshot_20210628.jpg');
g =rgb2gray(a);
arr=zeros(1,256);
[x,y,z]=size(g);
for i=1:x
for j=1:y
m=g(i,j)+1;
arr(m)=arr(m)+1;
end
end
stem(arr);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by