How to create array with unequal spacing?

9 ビュー (過去 30 日間)
Ahmad Hasnain
Ahmad Hasnain 2018 年 2 月 21 日
コメント済み: Walter Roberson 2018 年 2 月 22 日
I want to create an array with unequal spacing. I have h = 1 1/2 1/4 1/8 ..... 2^-60.
Every second entry in this array is 1/2 of the last one. I only know, how to make arrays with equal spacing.
a = 1:5:40
But how do I create array that gets halved with every entry?
  5 件のコメント
Stephen23
Stephen23 2018 年 2 月 22 日
@Walter Roberson: Interesting. So what is the usecase for pow2(n) then?
Walter Roberson
Walter Roberson 2018 年 2 月 22 日
In 2.^-(0:60) the JIT is detecting that the expression is constant and optimizes it, at least in the case of re-use. If you use B = 2; B.^-(0:60) or if you use V = -(0:60); 2.^B then JIT optimization is not as good and pow2 can have better performance than those.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 21 日
h = 2.^-(0:60);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by