What should I do?-Array indices must be positive integers or logical values.
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Worrakarn Panyaboon
il 26 Ago 2021
Commentato: Worrakarn Panyaboon
il 26 Ago 2021
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 Commento
Stephen23
il 26 Ago 2021
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.
Risposta accettata
Wan Ji
il 26 Ago 2021
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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Histograms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!