How to make a loop to the if else situation ?

2 ビュー (過去 30 日間)
Alvindra Pratama
Alvindra Pratama 2016 年 5 月 23 日
コメント済み: Alvindra Pratama 2016 年 5 月 24 日
I have a coding as follows:
if (idxi >=1) && (idxi <=5)
idx='1';
elseif (idxi >=6) && (idxi <=10)
idx='2';
elseif (idxi >=11) && (idxi <=15)
idx='3';
elseif (idxi >=16) && (idxi <=20)
idx='4';
elseif (idxi >=21) && (idxi <=25)
idx='5';
The following coding explained that I had a 25 images in a folder in the directory C. Here I make a conditional if, if idxi obtained has a range of 1-5, it is shown is data from mysql database that has idx = 1, when the idxi gained have 6-10 range, then that is displayed is the data from mysql database that has the idx = 2 and so on. But if I add as many as five images into the folder, it means I have to go back to add an if statement in the coding .. What I want to ask is, if I could make a loop so that I do not need to add a conditional if again if I add a new image?

採用された回答

Adam
Adam 2016 年 5 月 23 日
編集済み: Adam 2016 年 5 月 23 日
idx = num2str( ceil( idxi / 5 ) );
works if you will always have 5 images in each group and continue that same logic.
  4 件のコメント
Alvindra Pratama
Alvindra Pratama 2016 年 5 月 24 日
Sorry but the code you have been given not work with me
Alvindra Pratama
Alvindra Pratama 2016 年 5 月 24 日
Sorry for my comment above, your code relly really work for me, thank you so much & i apology for what i have said above

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

その他の回答 (0 件)

カテゴリ

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