App Designer - Duplicate/Clone/Copy Components
39 views (last 30 days)
Show older comments
Hi,
I am trying to clone some of my components in my App Designer app. I found the copyobj function but it does not satisfy my needs or I am not applying it correctly.
One example of what I try to do:
- App is started, uitable with is generated in the first tab within a uitabgroup and filled with some data on startup. This table should be saved invisible now including every property (Data, Format, Callbacks, ...) to be used later, maybe even multiple times.
- User makes some changes to this table.
- User presses a button that creates a new tab. Now the saved table from step 1 (not in the state after step 2) should appear in the new tab.
I marked the parts bold where my problem is.
Right now, I have a small empty panel to which I copy the table in the first step using copyobj and then copy it from there in the third step. Of course that is very dirty and doesn't even work properly as most properties are lost on the way even if I use the 'legacy' argument of copyobj.
A alternative approach would be getting all properties of the table and setting them to a new to create uitable. But I have no clue on how to do that.
1 Comment
Tommy
on 3 Jun 2020
Do you ever want to be able to "save" a table after the user has edited it? If not, why not just create your new table using the same syntax used to create the initial table?
If so, then you would need to somehow keep track of the properties which the user has edited, as each of those properties would no longer have (1) its default value or (2) the value you gave it when you called uitable() in the first place. A uitable has a lot of properties, many of which can't be changed through user interaction, so rather than storing every single property, it is probably easier to only store those properties which could change. (If the uitable for uifigures is anything like the uitable for figures, you may have trouble determining the column widths. However, other aspects of the table should be easy to determine and save.) Then in step 3 you would just create a new uitable and set all of the properties you saved.
To actually copy the entire table (or whatever graphics object you are working with), I believe you would need to make sure that every property is copied by value rather than by reference. You may find the following post useful:
Saving to a file and then reloading is an interesting idea...
Answers (2)
Sahithi Kanumarlapudi
on 3 Jun 2020
Hi,
You could modify the 'Parent' property of the table(say table1) to be 'tab2'. This will make the table to apper in tab2. You could do this using the below line of code
app.table1.Parent = app.tab2;
And assuming that by table being invisible, you mean that you do not want the user to view the table then you could set the 'Visible' property of the app to be 0 as following
app.table1.Visible = 0;
For more information on UITable properties, you could refer to the following links
2 Comments
Sahithi Kanumarlapudi
on 4 Jun 2020
Could you provide more information on how you have used 'copyobj' function.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!