Increase determine step size

9 ビュー (過去 30 日間)
Kostas Tsakos
Kostas Tsakos 2018 年 4 月 27 日
回答済み: Image Analyst 2022 年 8 月 9 日
Hello I want to have this steps (1,2,4,6,8).
How can I do it to be in the form of, for example:
n=5
n=1:2:((2*n)-2)

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 4 月 27 日
t = 1:5; steps = 3+(-53/12+(71/24+(-7/12+(1/24)*t).*t).*t).*t
I would suggest that you reconsider your task. It would, for example, have been much easier as
t = 1:5; steps = [1, (t(2:end)-1)*2]
  2 件のコメント
Kostas Tsakos
Kostas Tsakos 2018 年 4 月 27 日
I want the code to be x=1:times 2:8 (so i get 1,2,4,6,8)
Walter Roberson
Walter Roberson 2018 年 4 月 27 日
You cannot get that.
You can use (t-1)*2 + (t==1) or other ways of making an exception for the first value, but the 1 entry cannot be handled with a plain increment.
Now, if you had wanted [1, 2, 4, 8] without the 6 then that would have been easy: t = 1:4; 2.^(t-1)

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


Image Analyst
Image Analyst 2022 年 8 月 9 日
Try this:
n = 5;
n = [1,2:2:((2*n)-2)]
n = 1×5
1 2 4 6 8

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by