Matlab doesn't "Pause on Error" till Infinite recursion

4 次查看(过去 30 天)
Hello,
for a project I am working on I have to rewrite a .m-file. As it is quite complex (at least for me) I move forward by running the edited script, getting the next error message, fixing the issue and reapeat. This worked fine for my last few projects, however with this, it's different.
When Matlab hits a line it can't execute (e.g. a function that is not in the file path), it throws an error (as expected)...
Undefined function or variable 'Output_data'.
Error in wPLI_openfield (line 237)
data.trial{k} = Output_data((j:(k*10000)),:)';
...but won't stop computing for a few minutes or so (haven't timed it yet, maybe 2 - 4 minutes?). After that I get the following error message:
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
The recursion unlikely comes from the script (had the same problem with different m.-files) i am editing. I guess it has to be a more basic problem of Matlab or its core functions. But honestly, I just don't know.
As this is quite annoying and I don't know where it comes from, I hope some of you guys can help me with this issue. I already tried reinstalling everything twice.
I'm using Matlab2018a 9.4 on my Windows 10 Home 64 bit system.
  1 个评论
Adam
Adam 2019-11-14
Did you strip your path back to the minimum (just Mathworks folders plus a single folder for your own code) and see if you still get the problem?

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2019-11-14
Try setting a breakpoint on line 237 of wPLI_openfield. When MATLAB reaches that point, it will enter debug mode and the prompt will change to K>>. At this point, check that the fileparts and isrow functions that are being called are the ones written by MathWorks.
which -all fileparts
which -all isrow
This will check if there are fileparts or isrow functions in a directory that wPLI_openfield (or something called before wPLI_openfield) changes to with cd or adds to the path with addpath (but that the code normally changes away from or removes from the path before returning to the Command Prompt) and so were not "visible" to MATLAB when you checked before.
If that doesn't show anything, Walter may still be correct that there is a third-party toolbox interfering. To check this, can you show the list of products displayed when you execute the ver function? That's not foolproof (not all third-party toolboxes do what's needed to show up in ver, but it might show something that we've seen before and recognize as a potential cause.
  7 个评论
Walter Roberson
Walter Roberson 2019-11-14
Some of the toolboxes have installation instructions that talk about installing the compatibility directories or not, but most people do not look at those instructions.
Mark Schmid
Mark Schmid 2019-11-14
Thank you guys for helping me out!
I've checked the compat directory and indeed there were functions messing with built-in functions in Matlab. My Matlab version is sufficient and I don't need any of the compat functions so I removed the directory all together.
The README files suggested that there is an explanation when and why to add the compat directory to the Matlab path, but as I got the toolbox from a coworker alongside the script I'm currently editing I haven't paid attention to the installation and setup details. My bad.
I've tried around with Matlab and it seems like the issue is fixed.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-11-14
There are some third-party toolboxes that define isrow() and that interferes with MATLAB. Check
which -all isrow
What you see should start with a bunch of line similar to
built-in (/Applications/MATLAB_R2019b.app/toolbox/matlab/elmat/isrow)
built-in (/Applications/MATLAB_R2019b.app/toolbox/matlab/elmat/@cell/isrow) % cell method
built-in (/Applications/MATLAB_R2019b.app/toolbox/matlab/elmat/@char/isrow) % char method
You should not see any .m files listed until
/Applications/MATLAB_R2019b.app/toolbox/matlab/timefun/@datetime/datetime.m % datetime method
and a few others that are obviously from Mathworks.
What you will probably see instead is the first one being a .m from some third party code. You will need to use pathtool to locate the directory that code is in, and move it to the end of your MATLAB path, and save.
  2 个评论
Mark Schmid
Mark Schmid 2019-11-14
Hey thanks for the advice,
I tried
which -all isrow
and this is what I get:
built-in (C:\Program Files\MATLAB\R2018a\toolbox\matlab\elmat\isrow)
isrow is a built-in method % string method
C:\Program Files\MATLAB\R2018a\toolbox\matlab\datatypes\@categorical\isrow.m % categorical method
C:\Program Files\MATLAB\R2018a\toolbox\matlab\bigdata\@tall\isrow.m % tall method
C:\Program Files\MATLAB\R2018a\toolbox\distcomp\parallel\@distributed\isrow.m % distributed method
Seems to me they're all coming from Mathworks though.
I've found a solution searching for a way to fix Matlab being slow after running a script which takes up much of the memory (https://de.mathworks.com/matlabcentral/answers/438806-why-is-matlab-slow-with-large-objects-in-the-workspace-even-when-ram-is-not-limited).
The answer was simply hiding the workspace window and this seems to have fixed my initial issue as well. Probably there's something going on with the display of the used variables.
Mark Schmid
Mark Schmid 2019-11-14
Okay I'm back to square one, as it throws the same error message again after running the script. This time I haven't had an error in my m.-file. It just calculates a while, then I get this:
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
Out of memory. The likely cause is an infinite recursion within the
program.
Error in fileparts (line 40)
elseif ~isrow(file)
Even though my command prompt is active again (>>), it keeps throwing the same error. Like Matlab is stuck in the infinite recursion and every time the error occurs, it just clears the memory and starts all over again untill a few moments later the error occurs again. This happens about 6 to 7 times. It's very strange, I do not have a single clue what it could be and how to fix it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by