Ohio State nav bar

Customizing MATLAB Properties

July 1, 2019

Customizing MATLAB Properties

Ohio State seal

Getting Properties

A comprehensive list of user-manipulatable settings can be obtained by executing the following command at the MATLAB prompt:
 
get(0,’Factory’)
 
One of my least favorite MATLAB defaults is the grey background on all images and plots. The grey background can be changed to white by executing the following command at the MATLAB prompt:
 
set(0,’defaultfigurecolor’, [1 1 1])
 
Blank MATLAB plot showing the default grey background
Figure 1. a) Default MATLAB plot with grey background; b) Custom MATLAB plot with white background
 

Changing Properties

The nature of my work puts me in contact with a variety of data types. I can use the above commands to set a default figure size that works for the majority of my figures, but the default image size is often insufficient for summary figures or those with large legends. My strategy for resizing larger figures is to generate one figure, resize manually, report the image size for reproducibility, and set that image size as the default for that figure type. In order to report the image size for special plots:
 
get(gcf,’OuterPosition’)
 
The output from this command will be four coordinates:
 
240 378 1060 493
 
In order to make this the default image size for figures of this type, input the coordinates into the following command AFTER plotting, but BEFORE saving the figure:
 
set(gcf,’OuterPosition’,[240 378 1060 493])
 

Saving Custom Properties Between Sessions

Thus far all of the changes we have made will need to be repeated each time you open MATLAB. If you have custom properties/settings you would like to persist between MATLAB sessions, you must place these commands into a file entitled: startup.m. This is a simple way to retain any custom settings that you wish to use every time you open MATLAB. Create a new MATLAB file and paste the commands you wish to execute each time you open MATLAB. Add a semicolon to the end of each line to suppress the output between lines (end the line). The commands in my startup.m file are shown below:
 
cd /Users/Parker/Dropbox/Research-JPE/Scripting/PCARootDir/PPyCl09_PCA-APaseData/
set(0,’defaultfigurecolor’,[1 1 1],’defaultAxesFontSize’,18,’defaultLineLineWidth’,3);
warning(’off’,’xlwrite:AddSheet’); warning(’off’,’MATLAB:table:ModifiedAndSavedVarnames’);
if ismac
 
javaaddpath(’/poi_library/poi-3.8-20120326.jar’);
javaaddpath(’/poi_library/poi-ooxml-3.8-20120326.jar’);
javaaddpath(’/poi_library/poi-ooxml-schemas-3.8-20120326.jar’);
javaaddpath(’/poi_library/xmlbeans-2.3.0.jar’);
javaaddpath(’/poi_library/dom4j-1.6.1.jar’);
javaaddpath(’/poi_library/stax-api-1.0.1.jar’);
end
 

Tips

  1. 0 refers to the graphics root object and is interchangeable with groot
  2. gcf is an acronym in MATLAB for get current figure
  3. in my startup.m file:
    1. line 3 turns off specific MATLAB warnings
    2. lines 4-11 load Java libraries which is beyond the scope of this blog post

Written by TPS Fellow Parker Evans

References

Altman, Y. Getting Default HG Property Values. UndocumentedMATLAB (2013). Available at: https://undocumentedmatlab.com/blog/getting-default-hg-property-values
 

News Filters: