At startup time, MATLAB automatically executes the file matlabrc.m . This function establishes the MATLAB path, sets the default figure size, and sets some uicontrol defaults.
matlabrc
At startup time, MATLAB automatically executes the file matlabrc.m . This function establishes the MATLAB path, sets the default figure size, and sets some uicontrol defaults. On multiuser or networked systems, system administrators can put any messages, definitions, or other code that applies to all users in theirmatlabrc.m file. The matlabrc.m file is reserved for system administrators. The file matlabrc.m invokes the startup.m file, if it exists on the search path MATLAB uses. Individual users should use the startup.m file to customize MATLAB startup.
startup
Create a startup.m file in your MATLAB startup folder and put the commands you want to execute at MATLAB startup in that file. startup executes commands of your choice when the MATLAB® program starts.
For example, your startup.m file might include physical constants, defaults for Handle Graphics properties, engineering conversion factors, or anything else you want predefined in your workspace.
To find which startup.m is being used, use the following command in MatLab command window
» which startup /home/username/startup.m |
If no startup file is available, create startup.m file in either of the following ways:
- create your own startup.m file using MATLAB startup template file. It can be located using startupsav command.
» which startupsav /usr/local/MATLAB/R2011a/toolbox/local/startupsav.m
- create startup.m file in the your path (or current directory), paste the following code in it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | % The file is executed when MATLAB starts up, if it exists anywhere % on the path. % Add directory to search path addpath /home/username/:/home/username/matlab/: %%%%%%%%%%% PLOT SETTINGS %%%%%%%%%%% set(0, 'DefaultTextFontSize', 12) ; % ---------- Axes settings ---------- set(0, 'DefaultAxesFontSize', 12) ; set(0, 'DefaultAxesFontName', 'Helvetica'); set(0, 'DefaultAxesXGrid', 'on') ; set(0, 'DefaultAxesYGrid', 'on') ; set(0, 'DefaultAxesZGrid', 'on') ; set(0, 'DefaultAxesColorOrder',[0 0 0;0 0 1; 1 0 0; 0.9 0.9 0.9],... 'DefaultAxesLineStyleOrder','-|-*|-+') % ---------- Line settings ---------- set(0, 'DefaultLineLineWidth', 2) ; % ---------- Figure position ---------- set(0, 'DefaultFigureUnits', 'normalized'); %normalized,pixels set(0, 'DefaultFigurePosition',[0 0 0.4 0.3]); %[x y w h] set(0, 'DefaultFigurePaperPositionMode','auto') |
- Change the path(home/username) in Line-5 to meet your requirements.
- To print or export your the figures at the same size as they appear on the screen, modify the setting for DefaultFigurePaperPositionMode in your startup.m file to auto. By default it is in manual mode.
set(0,'DefaultFigurePaperPositionMode','auto')
- For the changes to take the effect, run startup in MatLab command window.
MatLab’s Path
Path is a variable which contains the list of directories that MATLAB looks in to find m-files.
When you type a command in the MATLAB command window, MATLAB decides what to do based on the following:
- First it searches for a variable in command space. If the variable by that name exists it will use it.
- If no variables match, then MATLAB looks in the current directory to see if there are any m-files that match the command name.
- If no m-files match in the current directory, then MATLAB looks through all directories in its path to see if there is an m-file in those directories whose name matches the command.
The path can be set either using addpath command or from the MatLab command window by navigating through File >> Set Path >> Add Folder
.
References
- MATLAB Startup folder
- http://www.mathworks.in/help/matlab/ref/matlabrc.html