While my goal here is to help you out with Matlab and other data analysis endeavors, I can’t cover the vast number of problem you may encounter. Still, I can provide you with a general approach that should help you to solve most problems. That is the goal of this post. I think everyone should be interested in this one, both the Matlab gurus and the beginners.
Coding is usually a long and solitary journey. You can’t share that keyboard and mouse so usually you will end up working by yourself most of the time. In some occasions, you will get stucked either by a bug or something you don’t understand or don’t know how to solve. At the beginning, this will happen VERY often and that is perfectly normal. Don’t despair, you have to go through this. I can already tell you that it gets a lot better as you understand better the language.
Still there are some things you can do to get going faster.
Let’s suppose you are working on a piece of code and something doesn’t work. It just doesn’t execute or doesn’t produce the result you would expect. You have looked at the code a thousand time and you just can’t get what’s wrong. Here is your to-do list :
- First, if it is 1 am and you have looked at this problem for 4 hours already. Stop! GO GET SOME SLEEP. I know, I have been there. It’s not worth it anymore. At this point, you have 90% chances that, in the morning, while you drink your morning coffee, you will just work it out without even having to look at the code.
- Now it’s the middle of the day and you still can’t solve it. Alright, now you need to look at this problem from a different angle. There are multiple ways to do this. Try to review all the functions that your program is using. Do you understand how all of them work? Accessing the help is very easy. For instance, for the ‘plot’ function, just type in :>> doc plot.If there is one function you don’t fully understand, it is likely the problem lies there. So do your homework and read the associated documentation.
- You are 100% sure you understand all the functions in your code and you still can’t figure it out. Alright, it’s BREAKPOINT and DEBUGGER time. Set a few breakpoints in your program and slowly step through your code. Check the content of all your variables as you step through. You should be able to identify exactly where your program starts to be boogie-woogie. If you have no experience in doing so, please consult my post on debugging.
- You have found where the problem starts but you still can’t get what’s wrong. Now it’s time to use your social skills. Even if you are programming by yourself, you could use some fresh eye on the problem. Ask around, even a new Matlab novice might have some ideas. 99% of the time, a new comer to your code will have a complete different perspective that will lead you to the solution. But be sure not to jump step 3: you need to be able to describe where the problem is as accurately as possible.
- Alright, if you are here, either you have no friends around (sorry about that) or they really have no clue. Now it’s time for our good old google. There are TONS of places online to look for solution to previously encountered problem :
First start with GOOGLE. Then look on multiple forums like : Matlab central and its newsgroups (tons and tons of stuff there), then go to stack overflow, check multiple blogs like mine, or Loren’s and Yair’s blogs.
- If you can’t find ANYONE who had the same problem before, this is dead serious. Your best chance from there is to ask a question on either stack overflow or Matlab newsgroups. I personally favor stack overflow, I got some extremely detailed answers in the past from very experience folks. You can also submit a support ticket to Mathworks if you have support through your license.
Feel free to add on or comment this list, and you : how do you go by solving your bugs?