How to create a sequence.

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

 采纳的回答

v = 2.^(1: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
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.
how to you know that!!!!!!!!!!!!!!!?????

请先登录,再进行评论。

更多回答(1 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by