필터 지우기
필터 지우기

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;
  댓글 수: 1
Stephen23
Stephen23 2021년 8월 26일
It looks like you are writing your own histogram code. Is there a reason why you cannot just use one of these?:
To fix that error remember that MATLAB indexing starts at one, not zero.

댓글을 달려면 로그인하십시오.

채택된 답변

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