Hello!(adsbygoogle = window.adsbygoogle || []).push({});

I consider myself typically a confident Matlab user. But I have encountered a new problem that I have no idea how to solve, so I'm hoping I can find some help.

I have set up a for loop in my code to the effect of

for i = 1:n

if MyArray(i,1) <some value

perform other calculations

end

end

The code runs fine for small values of n. But, when I have a very large n (somewhere near 50,000), I get an error message:

??? Attempted to access MyArray(NaN,1); index must be a positive integer or logical.

And, checking on the value of the index i, it has become NaN.

I don't understand how this is possible as Matlab should be incrementing i itself within the for loop. (I promise I'm not messing with the index inside the for loop!) I thought it might be a problem with the variable type of i, since I think values stored as integers have a relatively small limit, but it looked like i was stored as type long, which should be able to hold much larger than 50,000.

Does anyone have any suggestions? Your help is much appreciated!

-S

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab help: indexing in for loops

Loading...

Similar Threads - Matlab help indexing | Date |
---|---|

Matlab MATLab: Not enough inputs for nlinfit | Nov 16, 2017 |

Matlab Help needed to fix a matlab code | Nov 8, 2017 |

New to Matlab, help with vectors | Feb 20, 2016 |

Need help with integral | Dec 23, 2015 |

Communication between Arduino and Matlab Help | Jun 19, 2015 |

**Physics Forums - The Fusion of Science and Community**