Array indices must be positive integers or logical values?
Mostrar comentarios más antiguos
X=[1 2 3 4 5];for i=0:length(X) if mod(i,2)==0 f(i)=X(i); end end
1 comentario
Chinni Sai Ram
el 6 de Ag. de 2022
Respuestas (1)
John D'Errico
el 6 de Ag. de 2022
MATLAB does not allow an index of 0. The FIRST element of an array or vector is indexed as x(1).
In your loop, what was the range of the index i? You said
for i = 0:length(X)
So what does i start out as? (HINT: 0)
Now go back and read the first line I wrote.
Categorías
Más información sobre Multidimensional Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!