Very simple vectorization ?

1 view (last 30 days)
Geoff
Geoff on 6 Jun 2012
Good afternoon !
Is it possible to vectorize this short code ?
hello(1)=0;
for i=2:10
hello(i)=hello(i-1)+1;
end
Because the next one is effectively unappropriate :
hello=zeros(1,10);
i=2:1:10;
hello(i)=hello(i-1)+1;
Thank you for your answers !

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 6 Jun 2012
v = @(t1,dt,n)t1 + (0:n-1)*dt;
eg
v(0,1,10)
  3 Comments
Oleg Komarov
Oleg Komarov on 6 Jun 2012
Just execute the two lines sequentially.
Geoff
Geoff on 6 Jun 2012
Thank you :)

Sign in to comment.

More Answers (1)

Sean de Wolski
Sean de Wolski on 6 Jun 2012
hello = 0:9;

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!