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 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by