Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab assign a "export settings" -> "load settings from" for figures programmatically

Tags:

matlab

I have some figure styles I have saved in the "export settings" dialog that is accessed under File->"Export Setup".

Is there a way to load one of my styles programmatically? ie. I currently need to do a number of mouse clicks to load my desired style, then apply it to the figure, then tell it to export and give the file a name. I feel like all this should be doable through a few commands but I can't find the right information.

like image 518
lonestar21 Avatar asked May 15 '12 15:05

lonestar21


People also ask

How do I change export settings in MATLAB?

Apply your settings to another figure by opening the Export Setup box from its figure menu. In the Export Styles section, select the style name and click Load. Next, click Apply to Figure on the right side of the Export Setup dialog. MATLAB applies the saved style settings to the figure.

How do I export a figure in MATLAB?

Use the File > Export Setup dialog. Use Edit > Copy Figure to copy the figure's content to the system clipboard. For details, see Customize Figure Before Saving and Copy Figure to Clipboard from Edit Menu.

What does the figure command do in MATLAB?

figure( n ) finds a figure in which the Number property is equal to n , and makes it the current figure. If no figure exists with that property value, MATLAB® creates a new figure and sets its Number property to n .


2 Answers

I found this solution at the bottom of this thread:

 % create an example fig that we want to format with style file 'foo'
 plot(rand(14,10));

 % get style sheet info
 snam='foo'; % The name of your style file (NO extension)
 s=hgexport('readstyle',snam);

 %apply style sheet info
 fnam='myfig.jpeg'; % your file name
 s.Format = 'jpeg'; %I needed this to make it work but maybe you wont.
 hgexport(gcf,fnam,s);

And in your current folder should be a file called "myfig.jpeg" that is your figure with the export settings you made in "foo". If you want to see the style file options, type s into the command line. It should be a struct like this with all your export settings in it.

s = 

            Version: '1'
             Format: 'jpeg'
            Preview: 'none'
              Width: 'auto'
             Height: 'auto'
              Units: 'points'
              Color: 'rgb'
         Background: 'w'
      FixedFontSize: '10'
     ScaledFontSize: 'auto'
           FontMode: 'scaled'
        FontSizeMin: '8'
     FixedLineWidth: '1'
    ScaledLineWidth: 'auto'
           LineMode: 'scaled'
       LineWidthMin: '2'
           FontName: 'Wingdings'
         FontWeight: 'auto'
          FontAngle: 'auto'
       FontEncoding: 'latin1'
            PSLevel: '2'
           Renderer: 'auto'
         Resolution: 'auto'
       LineStyleMap: 'none'
         ApplyStyle: '0'
             Bounds: 'loose'
           LockAxes: 'on'
             ShowUI: 'on'
       SeparateText: 'off'
like image 92
kitchenette Avatar answered Nov 15 '22 08:11

kitchenette


Use the following "SDF" package from MATLAB central. It is just one line command. Put this sdf.m file in your path. Here is an example.

figure;
hold on;
plot(rand(1,100));
plot(rand(1,100), 'r');
grid on;
box on;
sdf('mystyle');          %"mystyle" is the name of export style

http://www.mathworks.com/matlabcentral/fileexchange/24807-sdf-set-the-figure

like image 32
Zubair Avatar answered Nov 15 '22 06:11

Zubair