Simple visual trick to minimize errors in your program.
We often encounter various errors while programming. Sometime it is very difficult to find, if the error is manual. I would like to share a trick to avoid the programming errors while writing a program in script file or function file.
Consider a simple example of "Finding sum of first 'n' numbers."
Following are the recurring errors we may encounter while programming -
You can check with Top-Right Corner of script/function file. The red color box represents the syntax error. The horizontal line below that makes it easier for us to find error command.
Error 1: Check with correct function file syntax to avoid this error (parenthesis). |
Error 2: No other command is allowed before function command. |
Error 3: End statement is missing. |
Warnings in the script/function file is denoted by orange color box. Warning is a suggestion by MATLAB to make program execute quicker. When warning is shown, the unnecessary output is printed in command window. When you see warning, you are just one step behind to make your program ideal.
Warning: The program will take more time to execute. |
The ideal program will always display the green box at Top-Right Corner. Even if the program shows green box, it can not detect manual errors.
Ideal Program: Program with no warnings and errors. |
Always keep good practice of making your program ideal. A reader can understand the ideal code quickly and easily, without much explanation.
Click HERE to subscribe to get regular email notifications of MATLAB Tips & Tricks.
Regards.
Rupesh Gosavi.
Comments
Post a Comment