# Index in position 1 is invalid. Array indices must be positive integers or logical values.

3 visualizaciones (últimos 30 días)
Xavier el 10 de Feb. de 2023
Comentada: Xavier el 10 de Feb. de 2023
I have :
c(i,2) = 272.0000
c(i,1) = 42.0000
and L(272.0000,42.0000) gives 2
but when I do
L( c(i,2), c(i,1) )
(L is a 697x103 double)
I got
Index in position 1 is invalid. Array indices must be positive integers or logical values.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Dyuman Joshi el 10 de Feb. de 2023
Editada: Dyuman Joshi el 10 de Feb. de 2023
The error occurs because your data is not exactly an integer even though it might look like it.
%Data displayed in the default format i.e. short format
y = 1.0000123
y = 1.0000
Type
format long
in your code and see the value of the the elements.
y
y =
1.000012300000000
Use round(), floor() or ceil() according to what you want to do.
L( round(c(i,2)), round(c(i,1)))
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Xavier el 10 de Feb. de 2023
Thank you very much for your answer, I tried with floor() and it works. It is quite surprising though because the value in c are from the use of ginput() so I thought it gives integers corresponding to a pixel.

Iniciar sesión para comentar.

### Más respuestas (1)

Mathieu NOE el 10 de Feb. de 2023
hello
depending of your format, the command window will display more or less decimals
I suspect
c(i,2) = 272.0000...............123
c(i,1) = 42.0000...............789
are not 100% integer so you have to round them to the nearest integer to make your code work
L( round(c(i,2)), round(c(i,1)) ) should now display the correct value
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Xavier el 10 de Feb. de 2023
Hello, thank you very much for your answer. You find the issue and it works now. Thank you !

Iniciar sesión para comentar.

### Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by