Index exceeds matrix dimensions

HI.
I've encouter an issue with Matlab.
I've a function which have for purpose to find in a dir take in input of the function the most recent dir/file in it and put the path of this dir/file in output.
I must run it with a 2015 MCR (Matlab compiler runtime) i've no problemes when i run it on Matlab 2020.
But when i try to run it with my 2015x Matlab version this msg came :
Index exceeds matrix dimensions (line where is the condition if)
Error in table/dotParentReference (l82)
Here is my code :
How can the index exceeds the matrix dimensions ?
Indeed i search dossier_a__chercher.datenum as many times i have dir/file in my current dir.
Nota : dossier_a_chercher_.datenum is a collumn. Do someone know if in the 2015 Matlab version we were able to acced at an element of a column like an element of a list as we can do with the current version ?
Sry for my english i hope this issue will be understandable
It would be very nice if someone has something to try !
Thx

5 Comments

Hi Tom, that's indeed strange... I would suggest checking the following:
  1. What's the value returned for nombre_dossier inside the function (line 2)? Just to make sure that it's not 0 and indeed corresponds to the number of files/folders in dossier.
  2. What is the value for i when the error occurs? You can use the debugger, or simply add a line i (without semicolon) before the if statement.
This does seem weird. You might also just check
length(dossier_a_chercher.name)
length(dossier_a_chercher.datenum)
to see if they give the same value ahead of the loop. I can't think of a circumstance in which they would give different values, but it might give a hint.
Hi John ! Thank you for your answer !
That's the difficult point : This function is run by the MCR x2015 this is just a little part of a big program but it's where the program encounter a probleme.
I have no issues when i'm running it on my computeur but this program is used by someone with the MCR x2015 directy in an executable program ( via a Human machine interface ) and i have no access on his computer so i cant use the debugger to find at which i value the issue occur.
I know there isn't a lot of informations to solve my issue :/
1. Normally nombre_dossier will never be equal to 0 indeed even if my input dir is empty it will always have '.' and '..' in my table furthermore even if nombre_dossier would be equal to 0 the for loop would came directly at the end and therefore the if statement will not be execute
2. I can't use it
I hope i have be clear in my situation...
Thank you John !
Was there a good reason to convert to a table instead of leaving it as a struct? It just means that you move the (i) indexing to the structure name instead of after the field name, and that you take length of the structure instead of length of the name field.
Hi Walter.
No there wasn't a good reason.
To be honest that's that's the first that i manipulate dir with matlab and when i saw table structure it was more meaningfull to me so i decide to work with it :/
Have a good (day or evening idk) !

Sign in to comment.

 Accepted Answer

Tom Argentin
Tom Argentin on 11 Mar 2021
Thank you for your answer the cyclist !
I will try to check and see if it is possible in a dir checked by matlab to have 2 differents lengths for those two elements
Thx

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!