MATLAB - Establishing a connection between a script and GUI popup menus

2 visualizaciones (últimos 30 días)
Valkyr
Valkyr el 21 de Oct. de 2014
Respondida: Valkyr el 27 de Oct. de 2014
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?

Respuestas (3)

Orion
Orion el 22 de Oct. de 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 comentarios
Adam
Adam el 24 de Oct. de 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.
Valkyr
Valkyr el 25 de Oct. de 2014
Yeah I did create it using GUIDE. I have edited nothing in the code that is automatically generated. (Well I've messed around with it but in it's current state it is as it was when first created).
There appears to be a callback for every popupmenu and produce graph button as expected. I have changed the tags on these to sensible names too.
Thanks for the response I will continue to mess around with it and get back to this thread when I've solved the issue and/or have another question.

Iniciar sesión para comentar.


Orion
Orion el 24 de Oct. de 2014
Editada: Orion el 24 de Oct. de 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 comentarios
Orion
Orion el 24 de Oct. de 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.
Valkyr
Valkyr el 25 de Oct. de 2014
Hi,
Thanks very much for taking the time to do this.
I'll check this out when I have the chance on Monday/Tuesday.
Really appreciate the useful response and I'll get back to this thread when I have solved the issue/have any more questions.

Iniciar sesión para comentar.


Valkyr
Valkyr el 27 de Oct. de 2014
Got it working guys cheers.
Turns out I needed to use str2num functions in my edit boxes for the input variables then have my loop do the work on getting the optimal values.
Putting all of this under the push button callback did the job.
Appreciate the help.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by