Recursion limit? [closed] - matlab

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
When I run my code on my laptop it runs without error,but when I run it from an old computer it throws me the error:
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer. Error in coder.allowpcode
I need to run my code from the old computer.I set also the recursion limit to a bigger value but my MATLAB program crash.

A 500 recursion is quite big, are you sure the code is good? Or are you recurring too often?
Assuming you code is good:
Your Matlab program crashes because you are causing a Stackoverflow (yeah that's why this site has that name and that logo!).
The Stack memory in a computer is a memory that saves a link to "where the function has been called". Nowadays, modern computers have a decent Stack memory, but old ones didn't. If you overflow that memory, when the execution of a code is "finishing" and getting out the functions to the parent function, eventually it won't know where to go (because there was no enough space in the Stack memory). This will cause a crash of your system (or Matlab).
There is nothing you can do about this (if your code is correct). Basically do not use big recursion in old computers.

Related

How can i beautify my code in Matlab (tabs, deleting unnecessary spaces etc.)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
i'm looking to find a way to beautify my code in MATLAB. I'm talking about tabs, deleting unnecessary spaces etc., the way Eclipse does it with Ctrl+Shift+F
The smart indentation (ctrl + I) is probably all you need (as #Matteo V and #Cris Luengo already mentioned).
However, there are a few other neat tricks that you might want to have a look at if you are really into code development:
Well, first have a look at the Improve Code Readability site of MATLAB. You could use the Apply smart indenting while typing option in the Preferences > MATLAB > Editor/Debugger > Language > Indenting section (it should be turned on per default but I like the Indent all functions setting). There are a bunch of other settings that you may want to explore
If you dig yourself deeper in the MATLAB IDE, you will notice that you can adjust almost everything to your preferences, but the way is not always documented in the web.... however, the local documentation (call doc) contains the info you may be looking for, see this blog-post
I am not aware of an automatic detection of double spaces or similar but you might end up writing your own little callback-function. Most languages ignore this anyway (perhaps except for Python). Code readability is usually a topic that the programmer(s) should care about... and not the machines ;)
Further tips:
respect the Right-hand text limit, which is the vertical gray line in your editor and shall indicate how many characters a single line of code should have as maximum. If it is a comment, wrap it. If it is an expression, try to outsource some commands to a dedicated variable
use equally long variable names. (There is no style guide as in Python, which says that you should use normal words and underscores etc) E.g. if you have two variables describing a commanded and a measured velocity, you could call them v_cmd and v_act and your code perfectly aligns if you apply the same manipulations to both variables ;)
use section. With %% (the space is important) at the beginning of a line in the editor, you create a section (you'll note the slight yellow background color and the bold writing that follows this command). It is convenient to structure your code. You can even run entire sections Editor-Tab > Run > Run section
Although there are programmers claiming that a good code speaks for itself (and therefore doesn't need any comments), to my experience writing comments has never been a bad idea. It improves the readability of your code
The answer might have been a bit elaborate for such an innocent question ... oO

Camera Fingerprint - Matlab implementation. Help me run this code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to run this code, but have reached a dead end due to my inexperience.
http://dde.binghamton.edu/download/camera_fingerprint/
The code is trying to call the Cpp fucntion mdwt in MATLAB, and that gives error. I changed the function call in MATLAB to coder.ceval but that gives the error "Too many output arguments." I would be grateful to anyone who would point out what I am doing wrong in implementing this code. Thanks in advance!
These files are source code for mex functions, which can be compiled using the mex command. The compile.m from the zip file contains the necessary commands to compile the mex files.

Unexpected MATLAB expression? (trying to create a function) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
load('matrix.mat');
userInput = input('input a value from 1-5')
DayReport = sum(matrix(:,end 2);==userInput)
I am trying to retrieve the number of rows in column 2 of the loaded matrix that corresponds with the userInput. However, when I try to run the code, it says that there is an error in the third line (simply, "Unexpected MATLAB expression"). Any ideas as to why this is?
EDIT: I found a solution, turns out i don't need the "end" or the semicolon within the sum function.
load('matrix.mat');
userInput = input('input a value from 1-5')
DayReport = sum(matrix(:,2)==userInput)
Remove the semi-colon and the end statement in the last line of code. My guess is that you want to access the second column of matrix, and with that it's just matrix(:,2).
Also, I suspect that you copied and pasted the code from somewhere. That's generally bad programming practice because where you copied the code from may work in that situation, but if you try and bring it into your current context, it may be slightly different than what you're actually doing and can result in errors.
See this good discussion on Programmers Stack Exchange on why you should avoid this all together: https://softwareengineering.stackexchange.com/questions/87696/is-copy-paste-programming-bad

Netbeans 7.4 introduces "10 lines max" per method rule. Where does this rule come from? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
NetBeans 7.4 beta is currently available for public download, and it introduces a weird warning rule by default:
Method length is 16 lines (10 allowed)
My question is: Is this an accepted code convention rule, that can be proven somehow, somewhere ? NetBeans support/devs say it's not a bug, but don't give a statement why they only allow 10 lines, and where exactly this rule has its origin.
You can change the maximum method/function length warning behavior in NetBeans options (it's under Tools->Options->Editor, in the Hints tab, under "Too Many Lines" section in the checkboxes list).
There you can set the maximum number of lines, how you would like to be warned, etc.
I believe that the rule was introduced by NetBeans developers because when working in teams, the automated tools that QAs use to "inspect" code flag long method declarations/functions bodies. Unfortunately, the use of automated tools by "code analysts" is on the rise, whilst their understanding of the reasons behind that are still limited. I do not say that your functions should be hundreds of lines long - that's just plain wrong, but a hard-coded number as a coding law - come on!
The "10 lines rule" has to do with enforcing test-driven development. The theory is that any method that has more than ten lines can be better broken down into units that are testable. it holds up in theory, but in practice a warning like this is more annoying than helpful.
I think there is not a convention about that, and it's very hard to make small functions in particular working in big projects.
I feel that the problem in NetBeans (or the rule) is counting lines with just one bracket or documentation.
This article gives him opinion about write functions with 5-15 lines.
I always disable this warning, as well as the warning about too many nested blocks. I understand the idea around not having large methods but a LOT of the time it's just not practical, and as someone else mentioned if you keep splitting your code into arbitrary functions just to appease the IDE you end up with spaghetti code jumping all over the place, refactoring becomes a huge problem later on as well.
Same as the line length limit warning, maybe a line 50 characters long made you scroll sideways in 1985, but today we have larger monitors (in color now as well!). I've seen people mutilate a line of code by shortening variable names so that it fits within the limit, turning a perfectly readable line of code into an indecipherable mess just so it fits within the limit.
Personally I think those three rules together have caused more garbage spaghetti code than helped create readable / testable code.
I think there is no such rule. I always thought a good convention would be no more lines of code in a class than one can read without scrolling. 10 lines seems not very much for me but in general it's for overview purposes and easier testing..

Increase Minimum Stack Overflow Size in Mac Common Lisp 5.0

I'm relatively new to Lisp (I just know the very basics) and I'm currently trying to run an algorithmic composition program created by David Cope. It runs in MCL 5.0, and I keep getting the following error:
Error in process play: Stack overflow on value stack.
To globally increase stack space, increase *minimum-stack-overflow-size*
Does anyone know what function I would use to increase the stack overflow size and how I would calculate the best stack overflow size for my computer? I'm running MCL on an old Powerbook with 512 MB of RAM.
Thanks for your time,
Eddie
Originally memory options were edited with ResEdit.
One can also use the SAVE-APPLICATION function and use the :MEMORY-OPTIONS keyword to specify various values. This is described in the MCL reference manual. This function saves a new MCL application. Typically one starts vanilla MCL, sets various options, loads some libraries and then saves a new application. This new application is then used during development.
The necessary stack size depends on the program you want to run.
If a stack overflow happens, in MCL you can continue with a larger stack in many cases. Just choose the right restart option.
It seems to say that you simply need to modify the special variable *minimum-stack-overflow-size*. When you are at the REPL (CL-USER> prompt or similar), inspect this variable by evaluating its name:
CL-USER> *minimum-stack-overflow-size*
Then, set it to a bigger value (the 1234567 is just a placeholder) with setf:
CL-USER> (setf *minimum-stack-overflow-size* 1234567)
However, this might not be the real issue. I do not know MCL well, but it might be necessary to (declaim (optimize (speed 3) (safety 0))) or similar to enable tail call elimination, if the program you want to run uses a tail recursive function which depends on such optimization.