Create a Doubling Series

조회 수: 14 (최근 30일)
Jordan Brewer
Jordan Brewer 2016년 9월 2일
댓글: Star Strider 2020년 9월 15일
I am trying to use Matlab to create a series in which each term is the double of the previous term (ie. 1*2=2, 2*2=4, 4*2=8 etc.), but I can't find an effective way to do this. Any tips?
  댓글 수: 1
Graham Bamford
Graham Bamford 2020년 9월 14일
How would you do this starting with any given number? i.e. starting with 250 and getting 500, 1000, 2000, 4000, 8000, etc...

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

답변 (1개)

Star Strider
Star Strider 2016년 9월 2일
Choose ‘limit’ to be whatever you want:
limit = 10;
Out = 2.^[1:limit];
fprintf(1, [repmat('%6d',1,limit) '\n' repmat('%6d',1,limit) '\n'], [[1:limit]; Out]')
1 2 3 4 5 6 7 8 9 10
2 4 8 16 32 64 128 256 512 1024
  댓글 수: 2
Graham Bamford
Graham Bamford 2020년 9월 14일
How would you do this starting with any given number? i.e. starting with 250 and getting 500, 1000, 2000, 4000, 8000, etc...
Star Strider
Star Strider 2020년 9월 15일
Graham Bamford —
Try this:
Out = 250 * 2 .^ (0:6)
producing:
Out =
250 500 1000 2000 4000 8000 16000
.

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by