Highlights
Follow


Help us help you: Post your code

Mike Croucher on 6 Jan 2022
Latest activity Reply by Stephen23 on 17 Jan 2022

Every day, thousands of people ask questions on MATLAB Answers and many of these are about their code. Questions such as “How can I make this faster?”, “Why do I get this error message?” or “Why don’t I get the answer I expect?”. There’s often one crucial thing missing though – the code in question!

Most of the people who answer questions on MATLAB Answers are volunteers from the community. They are answering your questions for fun, to learn more about MATLAB or just because they like to be helpful. This is even true for people such as me who are MathWorks members of staff. It’s not part of my role to patrol the community, looking where I can help out. I do it because I like to do it.

Make it easier to help me help you.

Imagine you’re a volunteer, looking for something interesting to answer. What kind of questions are you more likely to dig into and help an anonymous stranger figure out?

In my case, I almost always focus on problems that I can easily reproduce. I rarely know the answer to any question off the top of my head and so what I like to do is start off with the problem you are facing and use the various tools available to me such as the profiler or debugger to figure it out. This is the fun of it all for me – I almost always learn something by doing this and you get helped out as a side effect!

The easier I can reproduce your issue, the more likely I am to get started. If I can’t reproduce anything and the answer isn’t immediately obvious to me I’ll just move onto the next question. One example that demonstrates this perfectly is a case where someone’s MATLAB code was running too slowly. All of the code was available so I could run it on my machine, profile it and provide a speed-up of almost 150x.

It's not always feasible or desirable to post all of your code in which case you need to come up with a minimal, reproducible example. What’s the smallest amount of code and data you can post that I can run on my machine and see what you see? This may be more work for you but it will greatly increase your chances of receiving an answer to your question.

Stephen23
Stephen23 on 17 Jan 2022
  • Post short code in the body of your question.
  • Upload long code by clicking the paperclip button.
Adam Danz
Adam Danz on 6 Jan 2022

Thanks Mike. This is a useful reference to include in feedback to users in the forum.

Chen Lin
Chen Lin on 7 Jan 2022

Indeed. This is a simple but very useful tip for new users at Answers.

Tags

No tags entered yet.