MATLAB Answers

simplest way to build a series of numbers inside a for loop

1 view (last 30 days)
ddd ppp
ddd ppp on 21 Apr 2018
Commented: ddd ppp on 21 Apr 2018
im trying to build a series of numbers inside a for loop. here is what i used to do this.
t=0
dt=.1
ii=0
for i=1:10
% ii=[ii,i] %method one
t=[t,t(i)+dt] %method 2
end
is there a simpler method to do this?

Accepted Answer

Ameer Hamza
Ameer Hamza on 21 Apr 2018

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.

  3 Comments

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!