How do I copy figure properties from one to another? (2024)

82 views (last 30 days)

Show older comments

Aditya Zade on 2 Aug 2024 at 23:51

  • Link

    Direct link to this question

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another

  • Link

    Direct link to this question

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another

Commented: Walter Roberson on 3 Aug 2024 at 20:15

This question was flagged by dpb

Show flagsHide flags

  • Flagged as Not appropriate for MATLAB Answers by dpb on 3 Aug 2024 at 17:19.

    Don't use responders as tags, @Aditya Zade

  • Fig 1.fig
  • Fig 2.fig

I would like to copy the properties from Fig 1 to Fig 2. How can that be done?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (1)

Walter Roberson on 3 Aug 2024 at 17:41

  • Link

    Direct link to this answer

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#answer_1494256

  • Link

    Direct link to this answer

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#answer_1494256

Edited: Walter Roberson on 3 Aug 2024 at 17:43

Open in MATLAB Online

  • Fig 1.fig
  • Fig 2.fig

The below code sets all sensible properties.

fig1 = openfig('Fig 1.fig');

How do I copy figure properties from one to another? (3)

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 Comments

Show 8 older commentsHide 8 older comments

Aditya Zade on 3 Aug 2024 at 18:21

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228551

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228551

Edited: Aditya Zade on 3 Aug 2024 at 18:22

Oh, I think my question was ambiguous. I would like to implement all the figure properties from Fig 1 to Fig 2. Instead of changing the figure properties in Fig 2 manually, it would be nice if I can just copy figure properties of Fig 1 and paste those into Fig 2.

Umar on 3 Aug 2024 at 18:46

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228591

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228591

Edited: Walter Roberson on 3 Aug 2024 at 18:56

Open in MATLAB Online

To address your query, “I would like to implement all the figure properties from Fig 1 to Fig 2. Instead of changing the figure properties in Fig 2 manually, it would be nice if I can just copy figure properties of Fig 1 and paste those into Fig 2.”

% Get the figure properties of Fig 1

fig1 = figure('Visible', 'off'); % Create a temporary figure

copyobj(findobj('type','axes'), fig1); % Copy axes objects

fig1Props = get(fig1);

% Apply the figure properties to Fig 2

fig2 = figure('Visible', 'off'); % Create Fig 2

set(fig2, fig1Props); % Set Fig 2 properties same as Fig 1

% Display Fig 2

set(fig2, 'Visible', 'on');

So, as you can see the code snippet creates a temporary figure (Fig 1) to extract its properties and then applies those properties to a new figure (Fig 2). Finally, it displays Fig 2 with the copied properties. For more guidance on “copyobj” function, please refer to

https://www.mathworks.com/help/matlab/ref/copyobj.html

Hope this answers your question. Although, @Walter Robertson did answer your first question and he is very humble, doesn’t brag about his accomplishments, has years of experience and helping out us and even resolved many challenging problems. So, If I were you, I will take his advice into consideration as well.

Walter Roberson on 3 Aug 2024 at 18:50

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228601

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228601

You cannot copy all of the figure properties from Fig 1 to Fig 2.

  • there are a number of figure properties that simply cannot be set (read-only properties)
  • it does not make any sense to copy properties such as CurrentAxes, as they would refer to objects that exist in the first figure rather than objects that exist in the second figure
  • copying the Children property would be equivalent to copying the contents of the figure
  • the second figure has window style 'docked'. It is not permitted to set the various Position properties of something that is docked

it would be nice if I can just copy figure properties of Fig 1 and paste those into Fig 2.

It might be nice, but it isn't going to happen.

The code I provided copies all reasonable properties from figure 1 to figure 2.

Walter Roberson on 3 Aug 2024 at 18:59

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228616

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228616

Open in MATLAB Online

% Get the figure properties of Fig 1

fig1 = figure('Visible', 'off'); % Create a temporary figure

copyobj(findobj('type','axes'), fig1); % Copy axes objects

fig1Props = get(fig1);

fig1Props.CurrentCharacter

ans = 0x0 empty char array

% Apply the figure properties to Fig 2

fig2 = figure('Visible', 'off'); % Create Fig 2

set(fig2, fig1Props); % Set Fig 2 properties same as Fig 1

Error using matlab.ui.Figure/set
Error setting property 'CurrentCharacter' of class 'Figure':
Value must be a scalar char.

% Display Fig 2

set(fig2, 'Visible', 'on');

Aditya Zade on 3 Aug 2024 at 19:28

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228646

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228646

Edited: Aditya Zade on 3 Aug 2024 at 19:29

  • New Fig 2.fig

Thank you very much for responding.

However, when i am using your code, Walter, I get a new figure called "New Fig 2" with two figures inside. But, the data of original Fig 2 also gets replaced by the data of original Fig 1. I have attached the "New Fig 2" for your reference.

I am using this code:

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');

Umar on 3 Aug 2024 at 19:35

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228661

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228661

@Walter,

I do really appreciate your help by pointing this out.

Umar on 3 Aug 2024 at 19:39

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228671

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228671

Edited: Walter Roberson on 3 Aug 2024 at 19:49

Open in MATLAB Online

Hi @ Aditya Zade,

Please see updated code below, I modified the code and executed in matlab showing no errors which I should have done in the first place.

% Get the figure properties of Fig 1

fig1 = figure('Visible', 'off'); % Create a temporary figure

copyobj(findobj('type','axes'), fig1); % Copy axes objects

fig1Props = get(fig1);

% List all figure properties

fig1PropsList = get(fig1);

% Set Fig 2 properties same as Fig 1

fig2 = figure('Visible', 'off'); % Create Fig 2

set(fig2, 'Name', fig1PropsList.Name, ... % Set figure name

'NumberTitle', fig1PropsList.NumberTitle, ... % Set number title

'Color', fig1PropsList.Color, ... % Set figure color

'Position', fig1PropsList.Position, ... % Set figure position

'PaperPosition', fig1PropsList.PaperPosition, ... % Set paper position

'PaperSize', fig1PropsList.PaperSize, ... % Set paper size

'PaperType', fig1PropsList.PaperType); % Set paper type

% Display Fig 2

set(fig2, 'Visible', 'on');

By executing this code, Fig 2 will inherit the properties of Fig 1, allowing for a seamless transfer of figure properties without manual intervention. Hope, this answers your question.

Walter Roberson on 3 Aug 2024 at 19:58

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228701

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228701

Open in MATLAB Online

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');

Aditya Zade on 3 Aug 2024 at 20:11

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228716

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228716

Open in MATLAB Online

  • New Fig 2.fig
  • indp.png

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 on 3 Aug 2024 at 20:15

Direct link to this comment

https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228721

  • Link

    Direct link to this comment

    https://www-ah.mathworks.com/matlabcentral/answers/2142591-how-do-i-copy-figure-properties-from-one-to-another#comment_3228721

The legend of the plot is not a figure property: it is an axes property.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsPrinting and Saving

Find more on Printing and Saving in Help Center and File Exchange

Tags

  • star strider
  • walter roberson
  • torsten
  • dyuman joshi

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How do I copy figure properties from one to another? (14)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How do I copy figure properties from one to another? (2024)

FAQs

How do you copy properties from one object to another? ›

To Copy Properties From One Object to Other Objects
  1. Click Home tab > Properties panel > Match Properties. Find.
  2. Select the object from which you want to copy properties.
  3. If you want to specify which properties are copied, enter s (Settings). ...
  4. Select the objects to which you want to copy the properties, and press Enter.

How do I copy properties from one cell to another in Excel? ›

Select the cell with the formatting you want to copy. Select Home > Format Painter. Drag to select the cell or range you want to apply the formatting to. Release the mouse button and the formatting should now be applied.

How do you copy all properties from one object to another in blender? ›

Select more than one object, press Ctrl-C to copy attributes from active to selected, you'll see the following menu: Each item on the menu will copy some attributes from the active (last selected object) to all the other selected items: Copy Location. Copies the object location in world coordinates.

How do I copy a figure from one Word document to another? ›

Right-click the figure you want to copy from the source document. In the destination document, select "Insert" - "Object", and the appropriate graphical tool (e.g. Microsoft® Word Picture). MS Word opens the graphical software window: select "Edit" - "Paste Special" and choose the required output format.

How do you copy and paste properties? ›

Windows
  1. Ctrl Alt C to Copy properties.
  2. Ctrl Alt V to Paste properties.

How do you copy data from one object to another? ›

To copy objects in JavaScript, you typically have three options: using the assignment operator (=) for reference copying, performing a shallow copy using methods like Object. assign() or the spread operator (...) , and creating a deep copy using a combination of JSON. parse() and JSON.

How do you copy cell properties? ›

Select the cells that contain the data or other attributes that you want to copy. Click the first cell in the area where you want to paste what you copied. On the Home tab, click the arrow next to Paste, and then select Paste Special. Select the options you want.

How do you automatically copy values from one cell to another? ›

Use “= (equal) key” (Suitable for beginners)

Step 1: Select the cell where you want the formula to be created. Press the “= (equal)” key on your keyboard, then click on the cell containing the necessary value. The procedure is built for you using a cell reference. Step 2: Press the “Enter” key on your keyboard.

How do you copy specific data from one cell to another? ›

Select a cell or a cell range. Select Home > Cut or press Ctrl + X. Select a cell where you want to move the data. Select Home > Paste or press Ctrl + V.

How do you copy and paste a figure? ›

Press Ctrl + C (Windows) or ⌘ + C to copy the image. This will save the image to your temporary storage known as the Clipboard. Click in the document where you want to place the image. Press Ctrl + V (Windows) or ⌘ + V to paste the image.

How do you copy formatting from one item to another? ›

Tip: Use Alt+Ctrl+C to copy a format, and Alt+Ctrl+Vto paste a format. While the cursor does not change to a paintbrush, you can repeatedly select text and paste formatting to multiple areas without re-copying. To stop formatting, press ESC.

How do I extract a figure in Word? ›

This method is great when there are just a few images to extract. For this method, click on the image in the Word document using the right mouse button. From the pop-up menu, choose Save as Picture and then choose a directory to save into on your local drive. When there are a lot of images, this method can be tedious.

How do you copy properties from one object to another in Corel? ›

You can also copy fill or outline properties, or both, by right-clicking an object with the Pick tool , dragging over another object, and choosing Copy fill here, Copy outline here, or Copy all properties.

What is the command to copy properties from one object to another in Autocad? ›

You can use the MATCHPROP command to copy properties from one mtext object to another. If Text is selected on the Special Properties, MATCHPROP copies the text style, rotation, justification, and more.

Top Articles
Buzzcard Center Gatech
Words Their Way: Vocabulary For Elementary Mathematics Lori Helman Pdf
compose - Format data into multiple strings
Pwc Transparency Report
Burkes Outlet Credit Card Sign In
People Helping Others Property
Goodwill letter success! **UPDATE** new scores: EX 782; EQ 764; TU 769 no more baddies!
Pollen Levels Richmond
The 8 Best Santa Ynez Wineries to Visit in 2023
Creative Fall Bloxburg House Ideas For A Cozy Season
Craigslist Furniture By Owner Dallas
Thomas Funeral Home Sparta Nc
John Chiv Words Worth
Websites erstellen, benennen, kopieren oder löschen
Fintechzoommortgagecalculator.live Hours
35Mmx45Mm In Inches
Free Shredding Events Near Me 2023
Walgreens Dupont Tonkel
Video Program: Intermediate Rumba
Hotfixes: September 13, 2024
Strange World Showtimes Near Marcus La Crosse Cinema
Busted Newspaper Hampton County VA Mugshots
Dominion Post Obituaries Morgantown
2012 Buick Lacrosse Serpentine Belt Diagram
Auto-Mataru
Decree Of Spite Poe
All Added and Removed Players in NBA 2K25 (Help Us Catch 'Em All)
Pa Legion Baseball
Gopher Hockey Forum
New Orleans Magazine | Dining, Entertainment, Homes, Lifestyle and all things NOLA
Class B Permit Jobs
Aogf Causes.benevity
Usc Human Biology
Jvid Rina Sauce
Are your stomach problems caused by stress? What is ‘leaky gut’, and expert tips to avoid it
80 For Brady Showtimes Near Brenden Theatres Kingman 4
Harvestella Farming Guide | Locations & Crop Prices | TechRaptor
Leesburg Regional Medical Center Medical Records
Lkq Pull-A-Part
Papamurphys Near Me
Pixel Run 3D Unblocked
Aces Login Palo Alto
Aces Fmc Charting
Sacramento Library Overdrive
76 Games Unblocked Fnf
[PDF] (Indices und Systematiken) - Free Download PDF
Kathy Park Wedding
Albertville Memorial Funeral Home Obituaries
How To Spend a Day in Port Angeles (15 Things to Do!)
'It's something you dream about': This sparky quit his job to be a YouTube star
C-Reactive Protein (CRP) Test Understand the Test & Your Results
Backrooms Level 478
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 6345

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.