Whenever you encounter a problem that needs to be programmed, start with the naive solution. How would you do it by hand? Write it out step by step. If you are doing something over and over again then that may apply to a loop of some sort. There really is no way to get good at programming besides just programming. As you become familiar with the syntax and idioms within a language, the more adventurous you'll feel and the more complicated programs you can write.
Anyway, here are some tips that help me.
1. Don't immediately try to program an answer, take time to understand the problem and figure out how to do it by hand.
2. Don't be afraid to make mistakes. Programs are easy to change, so if you're not sure how something works, try it out and see for yourself.
3. In matlab, most things are done via vector type of operations, so be sure you are using the create arithmetic operator.
4. Understand that most people struggle initially with programming, so you're not alone.