- 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"
36 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2024-7-15,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.
回答(1 个)
Steven Lord
2024-7-15,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 个评论
Steven Lord
2024-7-15,23:24
Can you try running those two commands in MATLAB and showing us what they display?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!