I would like to know the basic principles and etiquette of writing a well structured code.
These are the most important two things to keep in mind when you are writing code:

Don't write code that you've already written.
Don't write code that you don't need to write.
Good practices in writing MATLAB code?