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!)
Clipboard01.png