Error: subscript indices must be either positive integers or logicals
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
This is my histogram function(histIntensity) with parameters M as a random image matrix and N as the maximal number of Bits
function vector = histIntensity(M,N)
x=rows(M);
y=columns(M);
vector=zeros(1,N);
for i=1:x
for j=1:y
if(M(i,j)<(N+1))
vector(M(i,j))++;
end
end
end
endfunction
And this is an image matrix (255x255) with vertical intensity variation:
T=zeros(255,255);
x=0:pi/254:pi;
y=sin(x/2);
plot(x,y);
T(:,:)=repmat(y,255,1);
imshow(T')
b=histIntensity(T,2^8)
bar(b)
But when i try to "call up" my histogram function it shows this error:
error: index (0): subscripts must be either integers 1 to (2^31)-1 or logicals
Could someone please tell me where is the mistake and what should i change?
Thank you :)
3 comentarios
David Hill
el 16 de Nov. de 2019
function vector = histIntensity(M,N)
x=rows(M);
y=columns(M);
vector=zeros(1,N);
for i=1:x
for j=1:y
if(M(i,j)<(N+1))
vector(M(i,j))++;%M(i,j) does not have to be an integer, you cannot index using it. What are you trying
%to do here? Also matlab does not recognize ++.
end
end
end
end
Respuestas (1)
Image Analyst
el 16 de Nov. de 2019
Editada: Image Analyst
el 16 de Nov. de 2019
In MATLAB, the code would be:
x=0:pi/254:pi;
y=sin(x/2);
plot(x,y);
T=repmat(y, [255,1]);
imshow(T);
axis('on', 'image');
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!