필터 지우기
필터 지우기

Half split a number in subsequents arrays.

조회 수: 1 (최근 30일)
Andre
Andre 2014년 3월 12일
답변: Sagar Damle 2014년 3월 12일
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
dpb
dpb 2014년 3월 12일
편집: dpb 2014년 3월 12일
Let's see your code...doesn't seem like it should take very much or be very slow.

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

답변 (1개)

Sagar Damle
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'

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by