You can simply use vector notation available in MATLAB as follow:
t = 0:0.1:1 ii = 0:10 % or ii = 0:1:10, if 2nd number is 1, it can be emitted.
The use of vector notation is also recommended because it is efficient and readable.
You can simply use vector notation available in MATLAB as follow:
t = 0:0.1:1 ii = 0:10 % or ii = 0:1:10, if 2nd number is 1, it can be emitted.
The use of vector notation is also recommended because it is efficient and readable.
So what do you mean by the simplest way? If you still want to use for loop then you can make improvement by pre-allocating the memory for the array as follow:
t=zeros(1, 11); %create 1x11 array of zeros dt=.1; ii=zeros(1, 11); for i=1:10 ii(i+1) = i; %method one t(i+1)= t(i)+dt; %method 2 end
This pre-allocation will show significant improvement in speed if t is a very large vector. Other than vectorization, it cannot get any simpler than this.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!