MATLAB - Establishing a connection between a script and GUI popup menus
3 views (last 30 days)
Show older comments
Hi,
I have created a MATLAB script which optimizes the geometry of the crane seen below so that the peak force (F) required from the hydraulic ram is at a minimum.
Next I plotted a graph of the optimized values of F against changing angles of theta. This gave the desired result.
I have then proceeded to make a GUI with the intent of varying the initial design constraints - for example the boom length OC, the load size, the ram retraction and extensions lengths - which will then alter the graph described above.
So far I have managed to design the following GUI (it should be noted that theta ranges from -20 to 80 degrees in the main design script):
The graph on the left side of the GUI is taken from the main script using a callback function set through the 'Produce Graph' push button - I realise this is probably the incorrect approach from my question below however felt it necessary to explain.
When I change the variables in the popup menus, the graph does not adjust.
My question is this: Using the varying design constraint values in the popup menus, how can I get the graph on the left side of the GUI to follow suit and adjust?
0 Comments
Answers (3)
Orion
on 22 Oct 2014
Hi,
it seems that you want the graph to be automatically updated when you change a popup.
in every callback of the popupmenus, you just need to add a call to the callback function associated to Produce Graph.
something like :
function popup_button1(hobject,event,handles)
% your code
% add a call to the push button callback
pushgraph_button1([],[],handles)
3 Comments
Adam
on 24 Oct 2014
Did you create your GUI in GUIDE?
If so and assuming you haven't changed the default options to tell it not to create an m-file and callbacks it will automatically create a callback of the type orion showed for each ui component you have (e.g. a push button).
I strongly recommend changing the default tags on your push buttons and other components to something sensible rather than just numbered push buttons, but that is an aside.
The first two arguments to the callback can largely be ignored for the functionality you want, but you should see them in your callback functions anyway (hObject and eventdata).
One thing you do need to do is turn your script into functions (I would use OOP and class(es), but functions will do fine).
You will need just small parts of your script in response to each UI component I assume so those parts need to be factored out into functions that you can call rather than trying to run a full script.
Orion
on 24 Oct 2014
Edited: Orion
on 24 Oct 2014
Hi,
I attached a simple gui made with guide to show you what I meant.
Changing the popupmenu will automatically call the callback of the pushbutton which will draw in the axe.
Note that the pushbutton is no longer useful with this kind of "updater" popup.
And the use of [] is just because pushbutton1_Callback has 3 input arguments, so I just give it 2 empty string, because these 2 first arguments are not used inside this function.
2 Comments
Orion
on 24 Oct 2014
Note : this kind of programming is not the neatest way to make guis, but it can be useful to continue your work and not being stucked.
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!