Half split a number in subsequents arrays.
1 次查看(过去 30 天)
显示 更早的评论
There is a know command to split (half) a number into subsequents arrays ?
Example 1: I give a number 100, and want to split it in 3 levels. 100 50 50 25 25 25 25
Example 2: I give a number 20, and want to split it in 4 levels. 20 10 10 10 10 5 5 5 5 5 5 5 5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5
...
and so on, my code is full of loopings and its slow.
Andre
1 个评论
回答(1 个)
Sagar Damle
2014-3-12
I don't know your code but I think this will help you.
number = 20;
level = 4;
answer = [];
for i = 0:level-1
answer = [answer,number/(2^i)*ones(1,2^i)];
end
answer'
0 个评论
另请参阅
类别
在 Help Center 和 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!