why do I receive "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
Rebecca D'Onofrio
el 2 de Sept. de 2021
Respondida: Daniel Pollard
el 2 de Sept. de 2021
B=6E-5;
MAT=zeros(26,26);
for i=1:26
for i=j
MAT(i,j)=[D*B+REM]
end
end
0 comentarios
Respuesta aceptada
Daniel Pollard
el 2 de Sept. de 2021
i and j in MATLAB both have the default value of the complex unit. When you say
for i = 1:26
you override this, so now i takes the value in that for loop.
When you say
for i = j
you then reset i to be equal to the complex unit again. This is not an integer or logical so cannot be used as an index. I supsect what you want to do is
B=6E-5;
MAT=zeros(26,26);
for ii = 1:26
for jj = 1:26
MAT(ii, jj)=[D*B+REM]
end
end
0 comentarios
Más respuestas (1)
KSSV
el 2 de Sept. de 2021
In MATLAB the indexing should be always positive integers and/ or logical.
A = rand(1,10) ;
A(1) % no error
A(10) % no error
idx = A>0.5
A(idx) % no error
A(1.5) % error becuase 1.5 is not integer
A(-1) % error neghative not allowed
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing 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!