>>13905271Okay, you really want some answers. With all these high level languages, there are dos and don'ts. Most of these boil down to trying to avoid for loops. For loops aren't bad, but almost all of these languages are already efficiently written as matrices and vectors so a lot of operations don't require for loops, just linear algebra. Using linear algebra over for loops is generally (I'm saying generally) cleaner and more effective than the for loop.
Secondly, if you want clean scripts, you gotta use that monkey brain. Make everything into a function that makes sense being a function. Generally (but not always), if you do something more than once, it should be a function. A.k.a. plotting the same type of graph for different data but with all the same settings. Take all these functions and put them into a SEPARATE script file and then call it at the beginning of your main file. A.k.a have a main.m file where everything is pulled together (this ideally shouldn't be very big, since most of the work should be done in functions) and a functions.m file where all the actual work is defined.
These functions need to be defined well too. Learn to use return commands, don't just use the default last computation unless it's super simple. Code in errors such as failure to converge and checks on all the inputs (you should know the limitations of what should be input into the function and should be able to write effective error checks in it like if x > 10 EXIT function and yell at user). Describe! Describe! Describe! Use your comments at the beginning of a functions to give a brief summary of the function then dedicate a line of comments to each input and each output
This also gets you into the habit of making your code more general and flexible since you're thinking about the extents of it's use. You can then go back and steal things effectively.
There are a lot of tricks to be done as well... But that's more advanced.