How can I repeat my setting for multiple figures (in different figure )?

39 次查看(过去 30 天)
I want to apply this changes to all of my figures:
figure('PaperUnits', 'inches','Units', 'inches',...
'PaperPosition', Possave,...
'PaperSize', sizesave,...
'Position', Poscreen,...
'PaperPositionMode', 'auto'); %'PaperType','A4');
axis auto;
set(gca,...
'Units','normalized',...
'FontUnits','points',...
'FontWeight','normal',... 'fontWeight','bold',...
'FontSize',14,...
'FontName','Times',...
'LineWidth',2,...
'box', 'off'); % default is off
set(legend,'FontSize',14,...
'linewidth', 0.3,...
'interpreter','latex',...
'TextColor',[0,0,0]);
and so on
How do I do that without the need of repeating my setting like this:
figure;
p=[plot(t,XEe,'-black'),plot(t,X,'or'),plot(t,XF,'+b'),...
plot(t,YEe,'-black'),plot(t,Y,'or'),plot(t,YF,'+b')];
set(p,'MarkerSize',10,'LineWidth',2);
figure;
p=[plot(t,XEe,'-black'),plot(t,X,'or'),...
plot(t,YEe,'-black'),plot(t,Y,'or'),];
set(p,'MarkerSize',10,'LineWidth',2);
figure;
p=[plot(t,XEe,'-black'),plot(t,XF,'+b'),...
plot(t,YEe,'-black'),plot(t,YF,'+b')];
set(p,'MarkerSize',10,'LineWidth',2);

采纳的回答

Stephen23
Stephen23 2017-11-21
编辑:Stephen23 2017-11-22
Two simple options:
  1. Set those value as defaults in the graphics root, then they will be used for all figures/axes/...
  2. Put the key-value pairs into a cell array, and then use a comma-separated list to input the values to the command:
figOpt = {'Position',[...], 'Papersize',[...],...};
axeOpt = {...};
...
figHnd = figure(...,figOpt{:});
axeHnd = axes(figHnd,...,axeOpt{:});
etc
  3 个评论
Stephen23
Stephen23 2017-11-21
编辑:Stephen23 2017-11-22
@work wolf: if you read the link I gave you it describes how to set the values back to the factory values.
"Please,do you know other method ?!"
Basically your choice is one of these:
  1. set the values in the root/figure/axes, in which case the values will be used by all children when they are created.
  2. set the values when the function is called/object is created.
  3. set the values of any object, after it has been created.
While there might be a few different syntaxes, these are your basic options. If the objects already exist then you will need to use their handles to set their values- This is one reaons why it is highly recommended to always obtain and use all graphics objects handles explicitly, and never relying on the current axes or figure being the one that you want to access. Many beginners rely on gca, gcf, etc, but this unpredictable and makes changing specific object properties very difficult. You need to obtain and use handles for all graphics objects that you use: figures, axes, lines, patches, images, etc. (see the example code in my answer). Then it is trivial to set their properties.
work wolf
work wolf 2017-11-21
编辑:work wolf 2017-11-21
Thanks again. Really, your answer is so clear and useful. Best Regards.

请先登录,再进行评论。

更多回答(1 个)

Nimrod
Nimrod 2019-1-3
help linkprop

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by