Stuart’s MATLAB Videos

Watch and Learn

MATLAB tip: Use one command per line 4

Posted by Doug Hull,

This is a common programming pattern that I see with new MATLAB users: They put more than one command per line in MATLAB file. This can make it harder to visually take in a file, and because profiler and error messages give information back based on the line number this practice will often hide the source command if they are nested or placed two on a line.

4 CommentsOldest to Newest

tunc replied on : 3 of 4
Doug, the reasoning for Matlab not being able to output the erroneous command is not quite reasonable to me since Matlab parses those lines in order to find the seperation in between the command (which is the semicolon). So Matlab really *does* know which command is faulty!? So why not then output the suspicious command? Or can give me a more exhaustive reason why not? Tunc
Doug replied on : 4 of 4
Tunc, I am not sure what the reason is for only giving the line number. It might be that the nomenclature "line 34, 3rd command" is just not very compelling. What I do know is that code is easier to understand, and work with existing MATLAB reporting when it is one command per line. Doug