App Designer - Duplicate/Clone/Copy Components

47 vues (au cours des 30 derniers jours)
Clemens Gersch
Clemens Gersch le 22 Mai 2020
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:
  1. 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.
  2. User makes some changes to this table.
  3. 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 commentaire
Tommy
Tommy le 3 Juin 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...

Connectez-vous pour commenter.

Réponses (2)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi le 3 Juin 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 commentaires
Clemens Gersch
Clemens Gersch le 3 Juin 2020
Then there would still be one table, right? First it is in tab1 and then in tab2. What I want to do is to make a copy of the table that already exists in tab1 to tab2, so that I have two identical tables regarding all properties with the only difference in the Parent-Property.
The 'invisible' part was not really meant to have an invisible component (or at least only in the case that there is no other possibility), more to have the component properties saved in the background to access them later. You could imagine a uitable that should be saved in its current state, then some properties are edited and later it is restored to the original state. That is what I try to achieve.
Sahithi Kanumarlapudi
Sahithi Kanumarlapudi le 4 Juin 2020
Could you provide more information on how you have used 'copyobj' function.

Connectez-vous pour commenter.


AYBARS DOGAN
AYBARS DOGAN le 28 Nov 2023
hello did you find a solution? I need same solution rn.

Catégories

En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by