How to insert pre-written functions into GUI
4 views (last 30 days)
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.
Brendan Hamm on 21 Jul 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:
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).
Jan on 22 Jul 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:
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