Skip iterations in for loop

3 ビュー (過去 30 日間)
Maud Hendriksen
Maud Hendriksen 2020 年 7 月 29 日
回答済み: Maud Hendriksen 2020 年 7 月 29 日
I need to skip iterations in my for loop. I have 46 columns in a matrix and want to adjust 36 of them.
I want to adjust the following 2 3 4 8 9 10 11 12 13 17 18 19 20 21 22 26 27 28 29 30 31 35 36 37 38 39 40 44 45 46. So 2:4 & 8:13 &. 17:22 &26:31 &35:40 & 44:46 and not the others
Thank you for any advice!
for i = 2:46
grf43.data(:,i) = grf43.data(:,i)-static_grf.data(1,i);
end

回答 (2 件)

Sriram Tadavarty
Sriram Tadavarty 2020 年 7 月 29 日
Hi Maud,
You can directly use those values for index i. Try this,
for i = [2:4 8:13 17:22 26:31 35:40 44:46]
grf43.data(:,i) = grf43.data(:,i)-static_grf.data(1,i);
end
Hope this helps.
Regards,
Sriram

Maud Hendriksen
Maud Hendriksen 2020 年 7 月 29 日
Thank you! I had tried that but thought it wasnt correct, turns out it is!

カテゴリ

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