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 Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by