Very simple vectorization ?

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 !

 採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 6 月 6 日

0 投票

v = @(t1,dt,n)t1 + (0:n-1)*dt;
eg
v(0,1,10)

3 件のコメント

Geoff
Geoff 2012 年 6 月 6 日
Excuse me, I haven't well understood. Could you apply your answer to my short example ?
Oleg Komarov
Oleg Komarov 2012 年 6 月 6 日
Just execute the two lines sequentially.
Geoff
Geoff 2012 年 6 月 6 日
Thank you :)

サインインしてコメントする。

その他の回答 (1 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by