Effacer les filtres
Effacer les filtres

opening .m file results in "index exceeds the number of array elements"

37 vues (au cours des 30 derniers jours)
Clifton
Clifton le 15 Juil 2024 à 17:19
Commenté : Steven Lord le 15 Juil 2024 à 23:24
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 commentaires
Clifton
Clifton le 15 Juil 2024 à 21:38
I am using Mac's Finder (file explorer) program to open the file (i.e., double-click with the mouse). My goal presently is just to read the script. I can work around the error message by opening with TextEdit. I have a research assistant that is well versed in MATLAB and they were surprised by the error message.
Walter Roberson
Walter Roberson le 15 Juil 2024 à 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.

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 15 Juil 2024 à 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
/MATLAB/toolbox/matlab/general/open.m /MATLAB/toolbox/matlab/uicomponents/uicomponents/+matlab/+ui/+container/@ContextMenu/open.m % matlab.ui.container.ContextMenu method open is a built-in method % Simulink.loadsave.SLXPackageReader method /MATLAB/toolbox/matlab/graph2d/@scribehandle/open.m % scribehandle method /MATLAB/toolbox/matlab/serial/@serial/open.m % serial method /MATLAB/toolbox/simulink/simulink/upgradeadvisor/@UpgradeAdvisor/open.p % UpgradeAdvisor method /MATLAB/toolbox/instrument/instrument/@icdevice/open.m % icdevice method /MATLAB/toolbox/shared/instrument/@instrument/open.m % instrument method /MATLAB/toolbox/sl3d/sl3d/@vrworld/open.m % vrworld method
which -all edit
/MATLAB/toolbox/matlab/codetools/edit.m /MATLAB/toolbox/shared/controllib/graphics/+controllib/+widget/+internal/+cstprefs/ToolboxPreferences.m % controllib.widget.internal.cstprefs.ToolboxPreferences method /MATLAB/toolbox/shared/controllib/graphics/@resppack/@respplot/edit.m % resppack.timeplot method /MATLAB/toolbox/matlab/graph2d/@axischild/edit.m % axischild method /MATLAB/toolbox/sl3d/sl3d/@vrworld/edit.m % vrworld method
If you have your own open.m or edit.m that shows up when you execute those commands, rename that file.
  3 commentaires
Clifton
Clifton le 15 Juil 2024 à 21:39
I am uncertain if replies to another thread get conveyed to all posters across other threads, so I'll reply to your similar question again here:
I am using Mac's Finder (file explorer) program to open the file (i.e., double-click with the mouse). My goal presently is just to read the script. I can work around the error message by opening with TextEdit. I have a research assistant that is well versed in MATLAB and they were surprised by the error message.
Steven Lord
Steven Lord le 15 Juil 2024 à 23:24
Can you try running those two commands in MATLAB and showing us what they display?

Connectez-vous pour commenter.

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by