Increase a variable proportionally to the squared number of loop repetitions

I have a program that loops ITERATIONS times.
I need to set a variable X that grows proportionally to the number of iterations.
The proportion is:
everytime the variable ITERATIONS is equal to 2^n then set X = n
Example:
ITERATIONS = 2 X = 1
ITERATIONS = 2^2 = 4 X = 2
ITERATIONS = 2^3 = 8 X = 3
ITERATIONS = 2^4 = 16 X = 4
How do I do this in matlab?
I was thinking something like:
If (ITERATIONS = 2^n) X= n
Am I on the right path?

 採用された回答

Mischa Kim
Mischa Kim 2014 年 1 月 18 日

0 投票

X = log2(ITERATIONS)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

タグ

質問済み:

2014 年 1 月 18 日

コメント済み:

2014 年 1 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by