Borrar filtros
Borrar filtros

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

37 visualizaciones (últimos 30 días)
Clifton
Clifton el 15 de Jul. de 2024 a las 17:19
Comentada: Steven Lord el 15 de Jul. de 2024 a las 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 comentarios
Clifton
Clifton el 15 de Jul. de 2024 a las 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 el 15 de Jul. de 2024 a las 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.

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 15 de Jul. de 2024 a las 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 comentarios
Clifton
Clifton el 15 de Jul. de 2024 a las 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 el 15 de Jul. de 2024 a las 23:24
Can you try running those two commands in MATLAB and showing us what they display?

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by