Please Help, I am getting this error "Index in position 1 is invalid. Array indices must be positive integers or logical values."
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Abubakar Abba
el 29 de Sept. de 2021
Editada: Abubakar Abba
el 29 de Sept. de 2021
I havean image (P) and generated 4000 random samples and stored in variable row and col. Then, from my image P, i want
to have array of P(row,col) position and the next horizontal Neighbour P(row,col+1).
P= imread('cameraman.tif');
for i = 1 : 4000
row = round(rand() * 255);
col = round(rand() * 255);
x(i) = P(row,col) ; % the first pix value
y(i) = P(row,(mod((col+1),256))); % the Horizontal neighbour
end
0 comentarios
Respuesta aceptada
Dave B
el 29 de Sept. de 2021
Editada: Dave B
el 29 de Sept. de 2021
If the result of calling rand is small (less than 1/255) then round(rand*255) will be 0, and 0 isn't a valid index.
Consider using randi(255) instead of rand*255? Or use something like ceil(rand*255) (as you're wrapping around for edge values with mod anyway)
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!