How do I copy figure properties from one to another?

13 Ansichten (letzte 30 Tage)
Aditya Zade
Aditya Zade am 2 Aug. 2024
Kommentiert: Walter Roberson am 3 Aug. 2024
I would like to copy the properties from Fig 1 to Fig 2. How can that be done?

Antworten (1)

Walter Roberson
Walter Roberson am 3 Aug. 2024
Bearbeitet: Walter Roberson am 3 Aug. 2024
The below code sets all sensible properties.
fig1 = openfig('Fig 1.fig');
fig2 = openfig('Fig 2.fig');
propnames = fieldnames(set(fig1));
if strcmp(fig2.WindowStyle, 'docked')
propnames = propnames(~ismember(propnames, ...
{'InnerPosition', ...
'OuterPosition', ...
'Position'}));
end
propnames = propnames(~ismember(propnames, ...
{ 'Children', ...
'CurrentAxes', ...
'CurrentCharacter', ...
'CurrentObject', ...
'CurrentPoint', ...
'FileName', ...
'IntegerHandle', ...
'Parent', }));
set(fig2, propnames, get(fig1, propnames));
savefig(fig2, 'New Fig 2.fig');
  10 Kommentare
Aditya Zade
Aditya Zade am 3 Aug. 2024
I might be doing someting wrong, but this code is still not copying properties into the newly created figure. The newly created figure is attached. This figure should look like the png that I have attached. I have manually entered all the properties to get this png.
fig1 = openfig('Fig 1.fig');
fig2 = openfig('Fig 2.fig');
fig3 = copyobj(fig2, groot);
propnames = fieldnames(set(fig1));
if strcmp(fig2.WindowStyle, 'docked')
propnames = propnames(~ismember(propnames, ...
{'InnerPosition', ...
'OuterPosition', ...
'Position'}));
end
propnames = propnames(~ismember(propnames, ...
{ 'Children', ...
'CurrentAxes', ...
'CurrentCharacter', ...
'CurrentObject', ...
'CurrentPoint', ...
'FileName', ...
'IntegerHandle', ...
'Parent', }));
set(fig3, propnames, get(fig1, propnames));
savefig(fig3, 'New Fig 2.fig', 'compact');
Walter Roberson
Walter Roberson am 3 Aug. 2024
The legend of the plot is not a figure property: it is an axes property.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by