MATLAB FUNCTIONS
EDITING FILES
Exit
Terminate MATLAB program (same as quit)
Syntax
exit
Description
exit terminates the current session of MATLAB after running finish.m, if the file finish.m exists. It performs the same as quit and takes the same termination options, such as force
Syntax
exit
Description
exit terminates the current session of MATLAB after running finish.m, if the file finish.m exists. It performs the same as quit and takes the same termination options, such as force
Matlab (Windows)
Start MATLAB program (Windows platforms)
Syntax
matlab helpOption
matlab -automation
matlab -c licensefile
matlab -jdb portnumber
matlab -logfile filename
matlab -nosplash
matlab -noFigureWindows
matlab -r "statement"
matlab -regserver
matlab -sd "startdir"
matlab shieldOption
matlab -singleCompThread
matlab -unregserver
matlab -wait
Syntax
matlab helpOption
matlab -automation
matlab -c licensefile
matlab -jdb portnumber
matlab -logfile filename
matlab -nosplash
matlab -noFigureWindows
matlab -r "statement"
matlab -regserver
matlab -sd "startdir"
matlab shieldOption
matlab -singleCompThread
matlab -unregserver
matlab -wait
Description
matlab is a script that runs the main MATLAB executable on Microsoft Windows platforms. (In this document, the term matlab refers to the script, and MATLAB refers to the main executable). Before actually initiating the execution of MATLAB, it configures the run-time environment by
- Determining the MATLAB root directory
- Determining the host machine architecture
- Selectively processing command line options with the rest passed to MATLAB.
- Setting certain MATLAB environment variables
- By specifying command line options
- By setting environment variables before calling the program
Options that you can enter at the command line are as follows:
matlab helpOption displays information that matches the specified helpOption argument without starting MATLAB. helpOption can be any one of the keywords shown in the table below. Enter only one helpOption keyword in a matlab statement.
Values for helpOption
Option | Description |
-help | Display matlab command usage. |
-h | The same as -help. |
-? | The same as -help. |
· matlab -automation starts MATLAB as an automation server. The server window is minimized, and the MATLAB splash screen does not display on startup.
· matlab -c licensefile starts MATLAB using the specified license file. The licensefile argument can have the form port@host. This option causes MATLAB to ignore the LM_LICENSE_FILE and MLM_LICENSE_FILE environment variables.
· matlab -jdb portnumber starts MATLAB, enabling use of the Java debugger. If you specify a port number, the Java debugger uses that port to communicate with MATLAB. You can specify any port number in the range 0-65535 that is not reserved or currently in use by another application on your system. By default, MATLAB uses port 4444. If you are running multiple MATLAB sessions and want to use the Java debugger, be sure to specify a port number.
· matlab -logfile filename starts MATLAB and makes a copy of any output to the Command Window in filename. This includes all crash reports.
· matlab -nosplash starts MATLAB, but does not display the splash screen during startup.
· matlab -noFigureWindows starts MATLAB, but disables the display of any figure windows in MATLAB.
· matlab -r "statement" starts MATLAB and executes the specified MATLAB statement. Any required file must be on the MATLAB search path or in the startup directory.
· matlab -regserver registers MATLAB as a Component Object Model (COM) server.
· matlab -sd "startdir" specifies the startup directory for MATLAB (the current directory in MATLAB after startup). The -sd option has been deprecated. For information about alternatives, see .
· matlab shieldOption provides the specified level of protection of the address space used by MATLAB during startup on Windows 32–bit platforms. It attempts to help ensure the largest contiguous block of memory available after startup, which is useful for processing large data sets.
· The shieldOption does this by ensuring resources such as DLLs, are loaded into locations that will not fragment the address space. With shieldOption set to a value other than none, address space is protected up to or after the processing of matlabrc. Use higher levels of protection to secure larger initial blocks of contiguous memory, however a higher level might not always provide a larger size block and might cause startup problems.
Prefdir
Folder containing preferences, history, and layout filesSyntax
prefdir
folder=prefdir
folder = prefdir(1)
Description
prefdir returns the folder that contains
- Preferences for MATLAB and related products (matlab.prf)
- Command history file (history.m)
- MATLAB shortcuts (shortcuts.xml)
- MATLAB desktop layout files (MATLABDesktop.xml and Your_Saved_LayoutMATLABLayout.xml)
- Other related files
folder = prefdir(1) creates a folder for preferences and related files if one does not exist. If the folder does exist, the name is assigned to folder.
Example
View the location of the preferences folder:
prefdir
Make the preferences folder become the current folder:
cd(prefdir)
% Then, view the files for customizing MathWorks products:
dir
On Windows platforms, go directly to the preferences folder in Microsoft Windows Explorer
winopen(prefdir)
preferences
Open Preferences dialog boxSyntax
preferencesDescription
preferences displays the Preferences dialog box, from which you can make changes to options for MATLAB and related products.Quit
Terminate MATLAB programSyntax
quitquit cancel
quit force
Description
quit displays a confirmation dialog box if the confirm upon quitting preference is selected, and if confirmed or if the confirmation preference is not selected, terminates MATLAB after running finish.m, if finish.m exists. The workspace is not automatically saved by quit. To save the workspace or perform other actions when quitting, create a finish.m file to perform those actions. For example, you can display a custom dialog box to confirm quitting using a finish.m file—see the following examples for details. If an error occurs while finish.m is running, quit is canceled so that you can correct your finish.m file without losing your workspace.quit cancel is for use in finish.m and cancels quitting. It has no effect anywhere else.
quit force bypasses finish.m and terminates MATLAB. Use this to override finish.m, for example, if an errant finish.m will not let you quit.
Examples
Two sample finish.m files are included with MATLAB. Use them to help you create your own finish.m, or rename one of the files to finish.m to use it.userpath
View or change user portion of search pathSyntax
userpath
userpath('newpath')
userpath('reset')
userpath('clear')
Description
· userpath returns a string specifying the user portion of the search path. The user portion of the search path is the first folder on the search path, above the folders supplied by MathWorks.
· The default folder is Documents/MATLAB on all platforms except Windows platforms released before Windows Vista™—for those Windows platforms, the default is My Documents/MATLAB. By default, the userpath folder is the current folder when you start up MATLAB — that is, it is the default startup folder.
· On Macintosh and UNIX platforms, you can automatically add additional subfolders to the top of the search path upon startup by specifying the path for the subfolders via the MATLABPATH environment variable.
· userpath('newpath') sets the userpath value to newpath. The newpath folder appears at the top of the search path immediately and at startup in future sessions. MATLAB removes the folder previously specified by userpath from the search path. newpath must be an absolute path.
· userpath('reset') sets the userpath value to the default for that platform, creating the Documents/MATLAB (or My Documents/MATLAB) folder, if it does not exist. MATLAB immediately adds the default folder to the top of the search path, and also adds it to the search path at startup in future sessions.
· userpath('clear') clears the value for userpath. MATLAB removes the folder previously specified by userpath from the search path.
Viewing userpath
This example assumes userpath is set to the default value on the Windows XP platform, My Documents\MATLAB. Start MATLAB and display the current folder:
cd
MATLAB returns:
C:\My Documents\MATLAB
where H is the drive at which My Documents is located for this example. Confirm the current folder is the userpath:
userpath
MATLAB returns:
C:\My Documents\MATLAB;
commandhistory
Open Command History window, or select it if already openSyntax
commandhistory
Description
commandhistory opens the MATLAB Command History window when it is closed, and selects the Command History window when it is open. The Command History window presents a log of the statements most recently run in the Command Window.
system
Execute operating system command and return resultSyntax
system('command')
[status, result] = system('command')
[status,result] = system('command','-echo')
Description
· system('command') calls the operating system to run the given command and directs the output to the MATLAB software. The command executes in a system shell, which might not be the shell from which you launched MATLAB.
· [status, result] = system('command') returns completion status to the status variable and returns the result of the command to the result variable.
· [status,result] = system('command','-echo') also forces the output to the Command Window.
The ampersand, &, character has special meaning. For console programs this causes the console to open. Omitting this character causes console programs to run iconically. For GUI programs, appending this character causes the application to run in the background. MATLAB continues processing.
Example
On a Windows system, display the current folder by accessing the operating system.
[status currdir] = system('cd')
status =
0
currdir =
D:\work\matlab\test
Demo
Access product demos via Help browserSyntax
demo
demo 'subtopic' 'category'
demo('subtopic', 'category')
Description
demo 'subtopic' 'category' displays the list of demos in the product or topic specified by category, where category belongs to subtopic. Allowable values for subtopic are: matlab, toolbox, simulink, and blockset. When subtopic is matlab or simulink, allowable values for category are the names of groups demos in those products. To specify all demos for the product when subtopic is matlab or simulink, do not specify category. When subtopic is toolbox, or blockset allowable values for category are products within the specified subtopic. For category, the product name is the toolbox folder for the product. To view the installed toolbox folders, run (fullfile(matlabroot, 'toolbox'))
demo('subtopic', 'category') is the function form of the syntax.
Examples
Display MATLAB demos that are in the Graphics category:
demo 'matlab' 'graphics'
(cont…)
No comments:
Post a Comment