How can I apply the format parameters of an existing figure to new figures?

92 ビュー (過去 30 日間)
Hi everyone I have a Figure that I spent a lot of time customising the colors, widths, etc, all from the Plot Tools GUI. I then have a script that generates figures, and I would like to be able to apply the formatting of my customised figure to the newly-generated figures. I tried two things:
1) Generate M-file from my customised figure, then create the new figures using that code. However, that gives some errors when passing the data parameters; the data is in a rather complex format so I'd rather not have to debug these errors
2) (what I thought would be easier) I opened my customised figure and did Export Setup, and saved as a new style, which I then loaded into a new figure. However, no changes were made to the style of the new figure.
Can anyone help? Many thanks!
  2 件のコメント
AwedBy Matlab
AwedBy Matlab 2013 年 12 月 20 日
Just wondering if this question is perhaps not in the right place, or not clear enough? Seems strange that I am getting no replies even though it's been posted for a while now. In the past I used to get replies within a few hours... Thanks for any clarification!
Asieh Daneshi
Asieh Daneshi 2018 年 10 月 2 日
That is easy! when you did all the changes, using"file> generate code" you can obtain the code that makes your figure. then you can use it to make other figures.

サインインしてコメントする。

採用された回答

MathWorks Support Team
MathWorks Support Team 2023 年 9 月 28 日
You can use a "cell" array containing the names of the properties of interest and then use the "set" and "get" functions to apply from "f1" to "f2". Please find a code sample below demonstrating this workflow:
% Create f1 figure
f1 = figure;
f1.WindowStyle = 'docked';
f1.Color = 'r';
% Now, we want to apply the same "WindowStyle" and "Color" from f1 to f2. We can do so using "cell" arrays and "get" and "set functions:
% Create a cell array of Properties you'd like to be consistent between f1 and f2.
desiredPropsToTransfer = {'WindowStyle', 'Color'};
% get the desired values from f1
desiredValuesToTransfer = get(f1, desiredPropsToTransfer);
% now apply the values to f2
set(f2, desiredPropsToTransfer , desiredValuesToTransfer);
To find additional information regarding the "set" command, you can consult the documentation page below:
To find additional information regarding the "get" command, you can consult the documentation page below:
To find additional information regarding "cell" arrays, you can consult the documentation page below: 

その他の回答 (2 件)

Matt J
Matt J 2013 年 12 月 20 日
編集済み: Matt J 2013 年 12 月 20 日
I guess something like the following might do it,
S=get(firstFigure);
set(newFigure,S);
  9 件のコメント
AwedBy Matlab
AwedBy Matlab 2014 年 1 月 28 日
Sorry, it may be that I am a bit confused. The kind of 'formatting' I was trying to re-use for future graphs were things like marker colour, font&size of axes' labels, legend position etc. Are these figure properties or axes properties, and can they be applied together as a 'style' (as in e.g. Word) when a new figure is created?
Thanks again for your help!!
Matt J
Matt J 2014 年 1 月 28 日
編集済み: Matt J 2014 年 1 月 28 日
>> docsearch Axes Properties
will lead you to a list of axes properties and similarly for figure properties. Marker color is a line property. Namely, the actual line objects that you place on axes using plotting commands are children of that axes and have their own properties. Each new line you add to a plot must have its individual properties set, either when created or post-modified. AFAIK, there is no axes property that will force all its child lines to have a certain color, marker type, etc...

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2014 年 1 月 28 日
編集済み: Sean de Wolski 2014 年 1 月 28 日
Use copyobj()
h = figure('color','r','name','Tuesday');
copyobj(h,0) % copy figure to root

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by