Introduction
Functions help keep MATLAB code neat and easy to understand. They let you reuse code without rewriting it.
When you want to repeat the same steps many times in your program.
When your code is getting long and hard to read.
When you want to test small parts of your program separately.
When you want to share your code with others in a clear way.
When you want to fix or improve one part without changing everything.