while loop index exceeds array elements problem
Show older comments
I am trying to run multiple iterations of this while loop to determine the reynolds number for various mass flow rates.. The first loop works perfectly, but when it gets to the second loop it gives me the error "Index exceeds array elements (1)" which is odd because I set up both loops the same way.. I tried reloading matlab but got the same

11 Comments
DGM
on 23 Mar 2021
Can you paste the actual text. I'm not eager to re-type everything from a picture and then guess which errors are caused by my own typos.
mason beal
on 23 Mar 2021
mason beal
on 23 Mar 2021
mason beal
on 23 Mar 2021
DGM
on 23 Mar 2021
Is this supposed to be using MFRF40N instead of MFRF30N?
REF40N(i+1) = 4*MFRF30N/(3.14159*AV*D1);
DGM
on 23 Mar 2021
So it is supposed to be MFRF40N? Did that fix anything or change the behavior?
FWIW, I was only looking at the pattern of the code.
REF30N(i+1) = 4*MFRF30N/(3.14159*AV*D1);
...
REF40N(i+1) = 4*MFRF30N/(3.14159*AV*D1);
...
REF50N(i+1) = 4*MFRF50N/(3.14159*AV*D1);
...
REF70N(i+1) = 4*MFRF70N/(3.14159*AV*D1);
...
REF80N(i+1) = 4*MFRF80N/(3.14159*AV*D1);
If we're still stuck, you're going to have to find a way to see which variable/line number it's throwing the error at.
Mathieu NOE
on 23 Mar 2021
hello Mason
maybe you should share also the data
mason beal
on 23 Mar 2021
mason beal
on 23 Mar 2021
mason beal
on 23 Mar 2021
DGM
on 23 Mar 2021
Glad to hear it!
Answers (1)
Veronica Taurino
on 23 Mar 2021
Edited: Veronica Taurino
on 23 Mar 2021
1 vote
Did you check your variable "i" has been set up to your desired value in the second while? Because in the first while you are updating it, so that the final value of ''i'' from the first "while" will be the input "i" for the second while.
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!