How to repeat the same number after certain interval in if statement?

I have a if statement in which certain value (e.g. nf) runs from 1 to 7 and from 8 to 16. I have some data to store for nf from runs 1 to 7 and another data from runs 8 to 16. For first run(1 to 7) I hav no issue and if statement execute with no error. For 2nd run when nf takes value 8 (8 to 16), I want to starts nf from 1(1 to 7) for this case again. Is there any way to do that?

 採用された回答

Star Strider
Star Strider 2018 年 10 月 21 日

0 投票

I am not certain that I understand what you want to do. You are apparently using only 14 of the 16 elements (or rows or columns) in your data set. If that is true, you can calculate the indices as:
idx = ceil(rem(nf,7.1));
This will ‘reset’ them to repeat the 1:7 series as long as you want.
You can test that with:
nf = 1:14
idx = ceil(rem(nf,7.1))
to see the result.

2 件のコメント

sam moor
sam moor 2018 年 10 月 22 日
thank you
Star Strider
Star Strider 2018 年 10 月 22 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2018 年 10 月 21 日

コメント済み:

2018 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by