How to insert pre-written functions into GUI

4 visualizzazioni (ultimi 30 giorni)
Faith McColl
Faith McColl il 21 Lug 2015
Commentato: Faith McColl il 22 Lug 2015
I found the online tutorial on how to make a simple GUI for Matlab (programmatically, not with GUJIDE). Once I have a GUI written in this format, how can I insert functions I have already made into this function to be accessed by push buttons? For instance, I have a function that plots the exceedance curve of the data and I want the user to be able to display this plot/data by pressing a button labeled "exceedance curve". I have version R2015a if that helps.

Risposte (2)

Brendan Hamm
Brendan Hamm il 21 Lug 2015
All that matters is that your pre-written function is on the MATLAB search path (and that it is the first one found). So for instance if I want to use the pre-written function myFunc. I can check if it is accesible by typing:
which myFunc
If the result is the location of the file on my computer, then I am all set to use this. Otherwise, add it using the instructions in the above link (It is good practice to add your function to the end of the search path).
  2 Commenti
Faith McColl
Faith McColl il 22 Lug 2015
Once I know the location of the file, how do I insert it into the GUI? Do I just put it in the GUI function as a command?
Jan
Jan il 22 Lug 2015
You do not need to know the location. All you have to know is if the function can be found by Matlab.

Accedi per commentare.


Jan
Jan il 22 Lug 2015
Your functions are treated exactly as all other Matlab commands. The code need not be copied into the file, which creates the GUI. Example:
function myGUI
FigH = figure;
ButtonH = uicontrol('String', 'Button', 'Callback', @myCallback);
function myCallback(ObjectH, EventData)
disp(sin(0.2)); % Call arbitrary Matlab functions
startMyIntegration(1,2,3); % Call your code
  1 Commento
Faith McColl
Faith McColl il 22 Lug 2015
When calling my code, is there a way to leave the variables open so different sets of data can be inserted? I'm trying to make this GUI flexible so it can be used for more than one set of data. Thank you for your help.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by