Filter löschen
Filter löschen

index no for iterations

1 Ansicht (letzte 30 Tage)
Nitheesh M
Nitheesh M am 25 Apr. 2015
Beantwortet: Stephen23 am 25 Apr. 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

Akzeptierte Antwort

Stephen23
Stephen23 am 25 Apr. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by