access an GUI axes from a different m file
Show older comments
Dear all, I have a problem with accessing axes from different m-file. In m-file #1, there is a pop-up button and a LED. Pop up button contains "NEW" and as soon as I select NEW, figure #2 will be opened. In figure 2, there is a button OK and whenever I press the OK, I need the LED change its colour. The problem is, I can not access the axes1 in m-file 1 and always get the message below:
Reference to non-existent field 'axes1'.
I have tried many ways like this: https://stackoverflow.com/questions/5346635/how-to-pass-parameters-to-a-matlab-gui-file
but still, nothing changed!
I would be very happy if someone could help! Thanks
1 Comment
Jan
on 4 Oct 2017
How can there be a "pop-up button" (what ever this is) inside an M file?! Or an LED? LEDs are real world objects, popup menus or buttons are GUI elements. Both do not exist in an M file. You do not find an axes1 inside the M files also.
This is not only nitpicking the terminology. It helps to solve the problem, if you formulate this exactly. Because then the translation from English to Matlab is much easier, or nearly trivial.
Post what you have tried so far. It is much easier to fix your code, than to guess all details of it.
Answers (1)
Jan
on 4 Oct 2017
There are different ways to provide the handle of the axes to the 2nd GUI:
- Forward the handles struct of the first GUI to the function, which opens the 2nd GUI and store a copy in the local handles struct there. The inputs must be caught in the OpeningFcn or CreateFcn - I'm not sure because IO do not work with GUIDE - do you?
- Give the axes a unique tag and use findobj to locate it from the 2nd GUI. This is less efficient, but the user might not even notice if a half second is wasted with searching all tags.
- You can identify the 1st GUI also by its tag:
GUI1 = findobj(allchild(groot), 'flat', 'Tag', 'theUniqueTagOfGUI1');
Then you can obtain its handle struct:
GUI1_handles = guidata(GUI1);
and access the axes1 object.
The first method is the fastest and safest. It would not be confused, if several versions of the same GUI are created.
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!