MATLAB: Am I getting error asIllegal use of reserved keyword ”end”
illegal use of reserved keyword end
While executing the attached code, I am getting an error showing illegal use of reserved keyword "end"
Best Answer
Probably because you have an end without a starting if. Even ignoring that line 1 and 4 should be a comment, I'm afraid to say your file is a complete mess. There's no indenting and you multiple statements on the same line, including if statements starting at the end of a list of statements.
Matlab smart indenting can't cope with that mess and even mlint give up with the message (on line 1): Code analysis did not complete. File contains too many syntax errors. And indeed if you look further down the problematic end it gets worse and worse, there's plenty of invalid statements.
I don't know where you've got this file but it's going to require a lot of work to fix. To start with, make sure there's only one statement per line (i.e. start a new line after each ;) and then make sure to use proper indentation.
After that, you'll have to figure out how to fix the mismatched end, the ... continuation that don't actually continue into something valid, the variable declarations in the middle of array constructions, etc.
Every single red line on the right of the editor is a syntax error that requires fixing. Orange lines are warning and probably an indication of a problem as well. You have lots of problems. See all these red lines (and more!)
Rather than using a separate report to debug this issue, set an error breakpoint. When it stops on a line where you create or use a griddedInterpolant look at the code that's being executed on that line and what variables you're using on that line.
If you don't see anything that explains to you what could cause that error, show us the line and the variables used on that line. The output of whos listing the class, size, and attributes of those variables may be useful.
The trailing "end" is a new feature in Matlab, which is required for nested functions. The old style without a trailing "end" will be kept for backward compatibility without any drawbacks. But when the programmer decides to use the new nested functions or the new style for one of the functions stored in an M-file, all functions must be closed by an "end" to keep the integrity.
Best Answer