フィルターのクリア

How to loop this operation ?

1 回表示 (過去 30 日間)
Andrea Di Lelio
Andrea Di Lelio 2019 年 9 月 12 日
回答済み: Andrei Bobrov 2019 年 9 月 12 日
Hello everybody,
I am trying to think about a loop in order to produce with 4/5 rows of code a simple result.
I have one vector of dimension 300x1 (called TarG) and the next ones are the operation that I would like to loop.
D_11 = TarG(300) / 100;
D_12 = (TarG(280) / TarG(281)) * D_11;
D_13 = (TarG(260) / TarG(261)) * D_12;
D_14 = (TarG(240) / TarG(241)) * D_13;
D_15 = (TarG(220) / TarG(221)) * D_14;
D_16 = (TarG(200) / TarG(201)) * D_15;
D_17 = (TarG(180) / TarG(181)) * D_16;
D_18 = (TarG(160) / TarG(161)) * D_17;
D_19 = (TarG(140) / TarG(141)) * D_18;
D_20 = (TarG(120) / TarG(121)) * D_19;
D_21 = (TarG(100) / TarG(101)) * D_20;
D_22 = (TarG(80) / TarG(81)) * D_21;
D_23 = (TarG(60) / TarG(61)) * D_22;
D_24 = (TarG(40) / TarG(41)) * D_23;
D_25 = (TarG(20) / TarG(21)) * D_24;
Tot_TarG = [D_11; D_12; D_13; D_14; D_15; D_16; D_17; D_18; D_19; D_20; D_21; D_22; D_23; D_24; D_25];
Is there someone that could help me?
Thanks in advance
  2 件のコメント
Stephen23
Stephen23 2019 年 9 月 12 日
編集済み: Stephen23 2019 年 9 月 12 日
What sizes are the very unfortunately named D_11, D_12, etc.?
Using numbered variables is s sign that you are doing something wrong. You should read this:
Andrea Di Lelio
Andrea Di Lelio 2019 年 9 月 12 日
編集済み: Andrea Di Lelio 2019 年 9 月 12 日
Each bad name is a single value. Those are just names now that I used to explain faster.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 9 月 12 日
ii = 300:-20:20;
D = TarG(ii)./[100;TarG(ii(2:end) + 1)];
Tot_TarG = cumprod(D);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by