- Are you trying to run (or execute) the code, or are you trying to modify (or edit) the code?
- When you you say "opening", can you describe how you are opening the file? Are you double-clicking on the file in the "Current Folder" browser? Or clicking the "Open" button on the MATLAB tool strip? Or something else?
opening .m file results in "index exceeds the number of array elements"
37 views (last 30 days)
Show older comments
I've yet to use MATLAB (new user) and since installing I've had issues with trying to open .m files from Finder (Mac). When opening .m file I get a dialog box that says "index exceeds the number of array elements. Index must not exceed 0"
3 Comments
Walter Roberson
on 15 Jul 2024 at 23:17
The most common cause of problems like these, is if you have some third-party function with the same name as a Mathworks-supplied function. For example if you have your own length.m then you can encounter these kind of problems.
Experiment with executing
restoredefaultpath; rehash toolboxcache
savepath
Note this will not work if the extra function is in the default directory.
Answers (1)
Steven Lord
on 15 Jul 2024 at 17:36
How are you trying to open the file? Are you calling open or edit with the name of the file as inputs? If so, make sure you don't have a variable with the same name as that function and check that you haven't written your own function by that name that's taking precedence over that function included in MATLAB.
which -all open
which -all edit
If you have your own open.m or edit.m that shows up when you execute those commands, rename that file.
3 Comments
Steven Lord
on 15 Jul 2024 at 23:24
Can you try running those two commands in MATLAB and showing us what they display?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!