I need to create a vector that holds a sequence. In the sequence the previous number is multiplied by 2. The sequence could stop at a desired number lets say 256 (but it could be a bigger number). How would one go about this?
Example sequnce = 2,4,8,16,32,...,256. vector = [2;4;8;16;32;64;128;256]
vector =
2
4
8
16
32
64
128
256

 채택된 답변

Sean de Wolski
Sean de Wolski 2014년 7월 23일

0 개 추천

v = 2.^(1:8).'

댓글 수: 5

Sandie Nhatien Vu
Sandie Nhatien Vu 2016년 8월 5일
Hi, i have a question.. How do i create that sequence using a for-loop? It should range:
2 4 8 16 32 64 128 256 512 1024 that is i = 1:10
for ii = 10
v = 2.^(1:ii).'
end
Stephen23
Stephen23 2016년 8월 5일
편집: Stephen23 2016년 8월 5일
@Sean de Wolski: that made me choke on my water with laughter... it really does fulfill the requirement perfectly, this wins the "best intentional misuse of a for-loop" prize.
Sandie Nhatien Vu
Sandie Nhatien Vu 2016년 8월 5일
Thanks a lot!
Simon Siu
Simon Siu 2020년 2월 5일
how to you know that!!!!!!!!!!!!!!!?????

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Morm My
Morm My 2021년 7월 29일

0 개 추천

thank you very much sir.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2014년 7월 23일

답변:

2021년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by