필터 지우기
필터 지우기

How do I copy figure properties from one to another?

조회 수: 92 (최근 30일)
Aditya Zade
Aditya Zade 2024년 8월 2일 23:51
댓글: Walter Roberson 2024년 8월 3일 20:15
I would like to copy the properties from Fig 1 to Fig 2. How can that be done?

답변 (1개)

Walter Roberson
Walter Roberson 2024년 8월 3일 17:41
편집: Walter Roberson 2024년 8월 3일 17:43
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
Aditya Zade
Aditya Zade 2024년 8월 3일 20:11
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 2024년 8월 3일 20:15
The legend of the plot is not a figure property: it is an axes property.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by