Ken & Mike on the MATLAB Desktop

June 25th, 2007

Creating an M-file from selections in the Command History

Getting started writing an M-file can be difficult sometimes. It’s akin to writing a term paper. That first bit is always difficult to write.

Often when I am writing M code, I start in the Command Window, rather than the Editor, to help get the initial part of the code working in a more interactive fashion. In the Command Window I can play around with the code until I get it right. I then go back later and put the code into a function in the Editor. But instead of copying code from the Command Window or the Command History and pasting it in the Editor, I use the Command History context menu: “Create M-File”.

History Create M file

The “Create M-File” context menu item opens an Editor window and pre-populates the new file with any selected commands from the Command History.

editor_history.jpg

The next time you find that you are working in this mode and you are ready to commit your code to a file, try using the “Create M-file” context menuitem from the Command History. This is easier and quicker than using copy/paste or re-typing the code.

4 Responses to “Creating an M-file from selections in the Command History”

  1. nkj replied on :

    i have Question I had been using the Matlab R2006b beta for mac intel and the matlab menus used to appear in the Mac OSX menu bar but in 2007a they appear in the main windows. Is there a way to switch back to the preivous way ?

    not sure if this is the right place but this is the dekstop team’s blog , i m hoping to find why the switch

  2. Kristin replied on :

    nkj -
    http://www.mathworks.com/support/bugreports/details.html?rp=230485

  3. nkj replied on :

    i tried this but on 2007a version does not seem to work

  4. Kristin replied on :

    Contact support@mathworks.com and they will be able to assist you further with this.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Ken & Mike work on the MATLAB Desktop team.
  • DP: Hi i have a problem with ezplot3, i want to plot more than i curve in the same graph but hold on command...
  • Ken: Hi Arsalan, Unfortunately there is no way to get the new Editor API in older versions of MATLAB. -Ken
  • Arsalan: Hi, I am very excited about the MATLAB API for editor because right now i am working on a project and i need...
  • Johannes: Since I started using matlab-emacs some days ago I never experienced Emacslink. But I experienced some...
  • Francisco J. Beron-Vera: Hi all, I have recently learned about ViEmu (http://www.vimemu.c om) which, for Vi/Vim...
  • OysterEngineer: When I first learned of the Publish feature in MatLab, I thought it might be useful to help to...
  • Ken: Hi Herve, I’m not quite sure what you mean by “stand-alone&# 8221; mode? -Ken
  • Herve: I wonder when the publish fonction will be supported in standalone mode.
  • Mike: Ravi, What you described should work as far I understand it. Please follow up with technical support. With a...
  • Mike: @Daniel, Thanks for that note.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.