How to copy figure children into uipanel

20 Ansichten (letzte 30 Tage)
Munie Ahmad
Munie Ahmad am 15 Mai 2014
Kommentiert: Munie Ahmad am 16 Mai 2014
Hi,
I created a GUI 4 years back, and it seems okay to copy children of a figure into uipanel back then, but now when I run the same GUI, I'm getting this error:
?? Error using ==> copyobj Object uimenu[21] can not be a child of parent uipanel[1]
here's the code I used:
copyobj(get(hf,'Children'),handles.result_panel);
'hf' is the figure with children that I want to copy to the uipanel (result_panel)
Examples are attached.
hf: 'resultfigure.png'
result_panel: inside 'gui.png'
I really hope someone has an answer to this, please advise. Many thanks.
Best regards.

Akzeptierte Antwort

Benjamin Avants
Benjamin Avants am 15 Mai 2014
I'd say the error is the result of trying to set the panel as a parent for an object that cannot have a panel as a parent. Knowing what type of object is causing your error should help figure out exactly what the problem is and how to avoid it.
Do you know what type of object uimenu[21] is? If the result panel only needs the labels and images, you should be able to pull those out of the list of children and only copy them. I believe all of the ui objects can be differentiated by either their 'Style' or 'Type' properties.
Maybe something like:
childObjects = get(hf,'Children');
types = get(childObjects,'Type');
uicontrolIndecies = strcmp(types,'uicontrol');
uicontrols = childObject(uicontrolIndecies);
copyobj(uicontrols,handles.result_panel);
Although you may need to manipulate the output from the get function before using strcmp...
perhaps an easier approach:
uicontrols = findall(hf,'Type','uicontrol','Parent',hf);
% Specifying the parent will remove children of children of hf from the list
copyobj(uicontrols,handles.result_panel);
If you have changed MATLAB versions since you first wrote the code, the java implementation of some of the ui objects you used may have changed, causing your error.
  1 Kommentar
Munie Ahmad
Munie Ahmad am 16 Mai 2014
Hi Ben, Thank you very much for your answer. It does solves the problem, but I used findall 'axes' instead:
uicontrols = findall(hf,'Type','axes','Parent',hf)
Then copyobj works smoothly. Thanks again!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by