Borrar filtros
Borrar filtros

index no for iterations

1 visualización (últimos 30 días)
Nitheesh M
Nitheesh M el 25 de Abr. de 2015
Respondida: Stephen23 el 25 de Abr. de 2015
Attempted to access x(2,1.01); index must be a positive integer or logical.
Error in ==> latest at 19 dx1=x(2,i);
my code ::
for i = 0:0.01:2 yd(j) = sin(2*pi*i); j=j+1; dx1=x(2,i);
should i be integer values only..if then my yd will always be 0 right..i need values of yd from 0 to 2..and corresponding dx1...
please help me out

Respuesta aceptada

Stephen23
Stephen23 el 25 de Abr. de 2015
You probably don't need a loop at all, and can simply vectorize the code anyway:
x = 0:0.01:2;
y = sin(2*pi*x);
and most likely any following value manipulations can also be vectorized. This is much faster and neater than using loops, which as something low-level programming languages rely on but are not a good use of MATLAB.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by