Despite the lack-luster title of this entry, I assure you that this new feature will be well worth the read, as it addresses one of our most common user requests!
In R2007b, you’ll notice a fancy new run button to the left of the debug toolbar (see Figure 1 below). The new split-button has a green play icon imposed on a document. Pressing the left side (with the icon) runs the currently selected configuration (I’ll explain what a configuration is in a minute), while pressing the right side (the downward facing arrow) will show you all the configurations for the file being edited.
Let me note that if you want to run your file as you used to, simply press the run button. Now, if you’re a little curious about what these new configurations can offer you, read on!
Configurations are small pieces of MATLAB code associated with a particular M-file. There can be many configurations associated with a given file, which can be very convenient as we’ll see below. When you first press the run button’s drop down arrow, you’ll see two menu items: the default configuration name (which happens to be the file/function name) as well as an option to edit configurations for the file you’re currently working with in the MATLAB Editor. If you select Edit Configurations for [your file] you’ll see the Configuration Editor (Figure 2 below).
Notice that by default, the name of the file you’re editing (which should also be the function name) is inserted into the default configuration as well as any subsequently created configurations. Running such a configuration would be identical to typing the file name at the command prompt.
This seems like such a complicated way to run a file, you say…ahh, but we haven’t arrived at the good part yet! Say your function (we’ll call it superFunction) takes an input argument. Previously in the MATLAB Editor, there would have been no way to run your function. You would have been forced to go to the command window and type superFunction(1234).
Creating multiple configurations allows you to easily change how you run a function. Each configuration can pass in different input arguments or it can call your function with a different number of input arguments (if your using varargin). You can even do some setup and/or cleanup in the configuration! If you had a surface you regularly created, you could have a configuration like this:
x = magic(20); x = x .* 2; surf(x); title('Magic Surface');
and maybe another like this:
x = magic(50); x = x .* 5; surf(x); title('Another Magic Surface');
Configurations are currently stored in a binary file, but we’re actively working on making their storage more transparent.
Configurations should help you stay focused on writing and testing your code…let us know what you think!
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.