MATLAB Answers


TUTORIAL: how to ask a question (on Answers) and get a fast answer

Asked by Oleg Komarov on 25 Apr 2011
Latest activity Edited by Chad Greene
on 23 Jun 2016


1) Before asking, did you search:

2) Post a substantial question in comprehensible English. Be brief, complete and clear (see also points 3-4).

3) Show what you have attempted so far and if you have got:

  • an error then post the whole error message. We need ALL the red text, not just a small part snipped out of it. This means line numbers, actual lines of code that generated the error, traceback to prior functions, etc. - everything that is in red color.
  • unwanted results then post a brief example of your inputs and the desired output.

4) If it's a homework problem or class assignment that you will be graded on, assign a tag of "homework" and read this.

5) Provide standalone and formatted code: how to format your question with markup. Use the paperclip icon to attach all m-files, fig files, data files (.mat, .txt, .csv, etc.) necessary for people to run your code. When attaching code, you need to click both the "Choose file" AND "Attach file" buttons. If you only click "Choose file" but do not then click "Attach file", it will not attach your file.

6) Before you click on the submit button, review your question in the preview pane (sometimes you need to "refresh").

7) Use the Products section to list the toolboxes that are relevant to your question. You don't need to list MATLAB - it's assumed that if MATLAB is not listed that you are using MATLAB.

8) If you are not using the current/latest version then say what version you are using . Sometimes functions come into existence at a particular version and if you have a really old version you may not be able to use the solution and you would need alternate solution that will work for your old version.

How to thank people who helped you:

1) If (and only if) one of the answers is the solution for your problem, click Accept this answer, and say thank you in a comment. Volunteers prefer a actual Thank You comment rather than a "thanks in advance" in your original question, and then never hear from you ever again (so they don't know whether their answer was even read by you). Note: once you officially Accept an Answer, it cannot be unaccepted so, if there are multiple Answers, be sure in advance that you have chosen the very best answer.

2) Vote for good answers. Voting and Accepting give the person "reputation points" which can earn them privileges in the forum. You can vote for more than one Answer and you can even Vote for the one you Accepted to give that author double reputation points.

3) Do not accept your own answer unless it is the best complete/detailed solution and you formulated it independently without using any of the information provided by the others who offered answers.



[Example 1] - How can I speed up this loop?

A = [];
for k = 1 : 10
   A = [A, k];

[Example 2] - I get an error, what's wrong?

>> foo
??? Subscript indices must either be real positive integers or logicals.
Error in ==> foo at 5

This is the function:

function foo
A = 1 : 10;
B = 0 : 1;
[tf, loc] = ismember(A, B);


[ III ] DON'Ts:

All of the following points are addressed in section [I] or by common sense.

  • Don't use demanding or commanding tone
  • Don't use textspeak such as plz, u, r, ur, kewl, abt, thx, b/c, etc. Some English speakers don't even know what those are, and it's even more difficult for non-native English speakers.
  • Don't ask for turn-key, ready to use code
  • Don't ask to solve your homework. Certainly don't just copy and paste your homework with not additional information about what you tried or what you are having trouble with. Read this homework tutorial.
  • Don't use URGENT in any part of your post and why your post is NOT urgent.
  • Don't assign useless tags that don't convey additional information, such as matlab, matlab code, matlab function, matrix, array, help, please, urgent, error, etc. Don't assign a tag of matlab coder unless you're actually using the MATLAB Coder product, and if then, list it in the product section.
  • Don't use HEEELP, MATLAB, PLEASE in your title. Use a meaningful title.
  • Don't post your code in the comments. Edit your original question adding formatted code.
  • Don't put the whole question into the subject line or the tag. Keep those short.
  • Don't post duplicate questions.
  • Don't post multiple answers on the same thread (don't rely on chronological order of answers then). Use comments.



  • You got a quick answer which solved your problem.


  • Some of the DON'Ts may apply to your post.
  • You have been asked to post more details.
  • You didn't format your code properly, so people cannot read it.
  • You have been tagged with: doit4me, givemecode, homework, assignment, no attempt, sendit2me etc. For a detailed description of the purpose and use of tags see: a guide to tags.
  • You got no Answers and no Comments at all.
  • Your question may be so esoteric, so specific that there are very few people who know how to answer your question, and perhaps the only one who can just has not seen it yet.

-------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------


In alphabetical order by nickname, thanks for their suggestions to:

Andrew Newell, Andy, Jan Simon, Jiro Doke, Matt Fig, Matt Tearle, Paulo Silva, Randy Souza, Rick Rosson, Sean de and Walter Roberson


Edits to enhance visibility of the post will not be recorded.

  • ...................... - created
  • 06 Aug 2011, 11:17 BST - added log
  • 07 Aug 2011, 00:05 BST - added tutorial series section
  • 08 Aug 2011, 06:16 BST - added other links section and changed links in section [I.4]
  • 18 Aug 2011, 01:44 BST - minor edits
  • 04 Sep 2011, 12:16 BST - [I.5] into [I.1] + reordered; new [I.5]; minor edits
  • 10 dec 2011, 19:09 GMT - minor edits to [I.2] and [III]
  • 20 Feb 2012, 14:38 GMT - added "refresh" suggestion to [I.5]
  • 22 Feb 2012, 17:30 GMT - edited [III], why your post is NOT urgent
  • 05 Jun 2012, 14:44 BST - Added link to MathWorks Documentation Center (Beta)
  • 02 Aug 2012, 19:34 BST - Added link to "A guide to tags" in [IV] and [OTHER Links]
  • 15 Oct 2012, 15:30 BST - Substituted link to Beta documentation (now adopted) with docs for Previous releases



-------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------

Please, suggestions are welcome.

Vote on Wish-list for MATLAB Answer sections my post if you think that a tutorial section on top of Answers could be useful.


Suppose if i have to attach a simulink model what I have to do? Please suggest.

Rahul: If it does not allow you to directly upload the model, then zip the model and attach the .zip.

This thread has 2400 views this month. The readers will profit as well as the complete forum does. Thanks, Oleg! +2400 :-)

Log in to comment.

12 Answers

Answer by Andy
on 16 May 2011


  • Check the FAQ.
  • Google search.
  • Make use of lookfor, doc, and help commands.
  • Try out simple code snippets yourself rather than asking about them.


  • Ask questions about an answer by entering another answer. (Use the "comment" feature. That's what it's there for. Answers will change order over time. Comments will not.)


jfgi and lmgtfy are not recommended.

Occasionally I suggest a search string for Google - as a comment, since it's not really worth submitting as an answer.

Log in to comment.

Answer by Rick Rosson
on 26 Aug 2011


  • Please include which release of MATLAB you are using, e.g. R12, R14, R2008b, R2011a, etc.
  • Please make sure it is clear which platform you are using, e.g. MATLAB, Simulink, Stateflow, SimEvents, SimScape, etc.
  • Please format your question and especially any code that you include. If you don't know how, please refer to Markup Help.
  • Please review your question in the Preview pane before you click on the Submit button. Check for spelling mistakes, typos, grammatical errors, formatting, and especially clarity. Put yourself in the shoes of someone who might try to answer your question. Did you make it easy or hard for them to answer your question?
  • Please review your question after you click on the Submit button. If you find any errors, omissions, or problems, please click on the Edit link and make the necessary corrections.
  • If you are satisfied with an answer, please let the person who posted that answer know so that he/she does not wonder whether it helped or not. Please Accept the answer and add a comment thanking the person for helping you.
  • If you are not satisfied with any of the answers to your question, please consider revising, clarifying, or adding more details to your question.


  • Please do not write a thesis or novel to explain the issue. Be concise. Enough said.
  • Please do not leave us guessing. Make sure you include enough information so that we can reproduce the issue ourselves in MATLAB or Simulink.
  • Please do not include ambiguous descriptions of the issue. Say what you mean, and mean what you say.
  • Please do not Accept an answer unless you are completely satisfied that it solves the issue raised by your question.
  • Please do not ask us to do your homework for you.
  • Please do not complain if no one answers your question right away. It is often (though not always) because you did not follow the advice in this tutorial.


Log in to comment.

Answer by Matt Tearle
on 5 May 2011

Do (if possible):

  • Give examples.
  • Provide standalone code. If not possible, give a thorough explanation of what the missing parts do/look like.


  • "How can I sort a vector according to values in another vector? For example if A = [5 2 7 4] & B = [0 6 2 3], I want the "sorted" B to be [6 3 0 2]"
  • "Here's my code. The load command on line 7 loads foo which is a 5-by-42 matrix of numbers between 0 and pi."

  1 Comment

Providing standalone code means attaching, with the paper clip icon , all the files necessary to run your program. This means the m-file, the data file, mat file, or image file (if you're using one), and the fig file if you're using GUIDE. We can't run your program if any of those files are needed but not supplied.

If your program is long, attach it , don't paste a 500 line long program into the code editor!

Log in to comment.

Answer by Andrew Newell
on 15 May 2011


  • Post duplicate questions.

If you feel that your question has been neglected, it may be because you didn't pay attention to the Do's. Try clarifying or adding more detail. This will have the added benefit of bumping your question back to the top of the queue.


Log in to comment.

Answer by Sean de Wolski
on 25 Apr 2011

  • Don't accept the first answer to come up! If an answer works for you THEN accept it. I.e. Don't accept it and then ask for an explanation or say "This doesn't really work!"


Log in to comment.

Answer by Paulo Silva
on 25 Apr 2011

  • Don't accept your own answer unless it's really the correct answer and you posted the detailed solution and/or the code
  • Don't forget to say thank you to those who tried to help you
  • If one of the answers is the solution for your problem do accept it and say thank you (Sean already had mention this one)
  • Vote on the best answers


Log in to comment.

Answer by Walter Roberson
on 11 Aug 2011

Do: post the relevant parts of your actual code, or a test-case that has been found to exhibit the same problem. If you leave any variables undefined in your code, describe their datatype and size.

Do not: type in an untested approximation of your code. You will probably make mistakes in variable names or in call syntax miss some details, and then people will end up debugging your typing mistakes instead of debugging your real difficulty,


Log in to comment.

Answer by Walter Roberson
on 1 Dec 2011


Phrase your post as a question.

The question should be more substantial than "How do I do this?" or "What is the code for this?".


Phrase your post in a way that other people might interpret as a demand or command !!

For example, "Send me the code for..." and "Write a program to..." would be interpreted as demands or commands. Especially "Write a program": that tends to get people upset, and even more upset if it is a homework assignment. This is not a homework-answering service, and the volunteers are here to learn and teach, not to be treated as servants and not to do assignments for people.

Asking "Please send me the code for..." is an improvement, but it still assumes that once someone found the code, that they would take the effort to email it to you (which could be time-consuming and even expensive for them.) Better would be to ask if someone could advise on where you could download the code.

If you must post a homework assignment, then be sure to distinguish your own words from the words of the assignment. Homework assignments should always be accompanied by a description of what you have done so far on the assignment, and a description of what it is that you are stuck on. People will think Bad Things about you if you post a homework assignment without adding your own commentary.


Log in to comment.

Answer by Sean de Wolski
on 8 Mar 2012

If you are getting a: Crash/SegV or Java Exception, contact technical support:

  1 Comment

I do not completely agree. On one hand the technical support rejects questions from student versions or students, who are using a site license without beeing associated with this license personally.
On the other hand I would add: "... execpt you are writing your own C-mex files - than debug your code by yourself at first."

Log in to comment.

Answer by uncung fgv on 1 May 2012

this tutorial make me afraid asking question here. you people cruel.


It's all about the mismatch in expectations and the delivery of the problem/solution.

This tutorial tries to establish some guidelines to get rid of these two problems and help the poster to get an accurate and fast answer.

Mismatch in expectations:
- posters form specific expectations on how contributors perceive their question;
- contributors have very different backgrounds.

Delivery of the question/answer:
- posters are exposed to the risk of forming a very narrow perception of the problem (the more you look at it the less you notice alternative solutions), and they may have conveyed the problem unclearly.
- contributors may propose a technically valid solution which however doesn't match the background of the poster in the result that disagreement bears the same meaning (but the solution is discarded by the poster).

One point that should actually be crystal clear to the poster: ignoring the suggestions of this tutorial will NOT add additional penalty to your question, i.e. unclear questions would get the same reaction even if this tutorial did not exist. The only way to improve is to build some awareness and minimal standards, and this is what I was trying to do.

This tutorial tries to eliminate the mismatch between uncorrect or biased expectations of the poster and the actual reaction of the contributors.

Suggestions for rephrasing are welcome.

There have been over 37000 Questions posted here in 16 months, an average of more than 75 Questions per day. A lot of what is written above is based upon experiences of what works efficiently and what does not.

I do not feel cruel. I've written "Please format the code as explained at the 'Markup help' link" more than 100 times. I do this, because a (more) readable question increases the chance to get a helpful answer. It would be more useful if all newcomers in this forum read the instructions at first, but to face the fact: they don't.

Log in to comment.

Answer by Thomas
on 1 May 2012

Maybe this post should be a 'sticky' post at the top of the answers forum..

  1 Comment

Log in to comment.

Answer by Chad Greene
on 23 Jun 2016
Edited by Chad Greene
on 23 Jun 2016

Phrases like "doesn't work" and "didn't work" do not sufficiently describe a problem.


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today