Day 23: How to discover your own MATLAB strategies and tips

Jozsef Meszaros
3 min readMay 25, 2020

Many of the tips that I outline in my ‘30 Days of MATLAB Tips’ rely on setting properties that most people don’t know about. Anyone can use the set function without any arguments to peek at all the possible properties and settings of a MATLAB object. Many of these properties and settings aren’t documented or aren’t well documented. And anyways, it’s much faster to see the options available to you than to go poring over documentation.

Here’s a quick demonstration and then a couple of cool examples of what you can do. Run the code below:

fig = figure();
imagesc( rand(10,10) )
set( fig )

The world will open up to you. There are so many properties with so many options that I can’t even make a normal image of them all.

Any of the words inside of the brackets are game on in terms of settings for that property. For example,

set( fig, 'WindowState', 'maximized' )

Will maximize your figure for you! This can save you a fair amount of time when you are displaying figures for someone that you’ve just made.

You can also do it in the cool dot notation way:

fig.WindowState = 'maximized'

Some of the figure properties aren’t written out, but they exist. Try, for example:

fig.Position

You can even do math with them. Push your figure around (or even all the way to a second monitor) by entering:

fig.Position = fig.Position + [100,0,0,0]

Below are a couple of cool properties that you might want to try

  • Tired of using loglog to plot your data? Make any type of graph and give it a log-axis.
figure(); bar([1:5],randi(100,1,5))
gca.YScale = 'log'

(By the way, gca is your current axis in case you didn’t know. And gcf is your current figure.)

  • Want to rotate your axes labels? That’s there, too.
gca.ZTickLabelRotation = 90 % Degrees
  • Don’t like the color map that MATLAB uses for your different plotlines but aren’t sure how to change it? There’s a property for that.
gca.Colormap = yourpalette

In the example above, yourpalette is a palette that you choose. To see all the pre-set palettes in MATLAB, try “doc colormap”. Or play with a few:

gca.Colormap = autumn(5)
gca.Colormap = winter(5)
gca.Colormap = jet(5)
% So on.
  • You can use set on *any* graphics object, even a plot line.

Try the code below:

figure;
t = plot([1:10]);
set(t)

This will allow you to see all of the “settable” properties of a line. My favorite:

Marker: {‘+’ ‘o’ ‘*’ ‘.’ ‘x’ ‘square’ ‘diamond’ ‘v’ ‘^’ ‘>’ ‘<’ ‘pentagram’ ‘hexagram’ ‘none’}

Just about anything that pops up in a MATLAB window has properties and settings that you can check using the set function. Try it with your pie charts, bar graphs, and scatter plots. The best part is that by checking the available settings with set, you can discover ways to optimize and cater your MATLAB experience to your personal needs.

--

--