My matlab software crashes when i run my code without giving any error log.
57 views (last 30 days)
I am trying to run this program. But when it reaches second for loop it crashes without any output. If I run it for one loop it is fine. Memory may be the issue here because of recursion. How can I manage the memory? Program files are attached.
OCDER on 24 Sep 2018
Before fixing memory issues, without getting an "Memory Error" message that would suggest this is the issue, perhaps look into rewriting your code to avoid scripts, clear, global and eval. These are much larger issues than your crashing error - which should resolve itself when you rework your code using best practices.
global: it's hard to figure out what operation is modifying your variables, and in what order. Use regular variables and pass them into your functions as inputs.
script: does not compartmentalize your tasks, which means you'll end up using clear to clear up memory, which is very slow and makes your code much more difficult to maintain as you must search and clear variables you don't need. Also, functions will generate an error if something goes wrong, so you can debug just that function.
clear: takes up a lot of time and it's hard to keep track of temporary variables. With functions, temporary variables are automatically cleared when function completes, saving only the outputs.
eval: worst function to use, as matlab cannot pre-check your code for potential error, as in anything can go and crash your computer. You need to use the appropriate function name instead
Read these blogs for starters, and begin reworking your code. Also, use debugging tools. For crashes, consider running your code line-by-line until it crashes (hopefully, your reworked code won't crash but will return an error message instead).
BAD PRACTICES https://blogs.mathworks.com/videos/2010/03/08/top-10-matlab-code-practices-that-make-me-cry/