index no for iterations

1 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2015-4-25
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by