Connecting an outside function to a GUI.

I have a function file that I made for the first part of my project and the second part is to take it and make it into a GUI. Right now I have the layout of the GUI set up and I need to connect my function file. The GUI is set up so that you can choose between a Surf, contour, and 2D plots. Then you input values that will then plot the function. How would I go about connecting our previous function to the axes on the GUI. Any help will be appreciated.

回答(1 个)

Jan
Jan 2017-12-6
编辑:Jan 2017-12-6
The question is a little bit vague, so I cannot suggest explicit code. But the general idea is to keep the GUI and the calculations separately. At first create all input data in the GUI and store them in its ApplicationData (see guidata and the handles struct) or UserData. Then start the calculations with a callback, e.g. of a button called "Start".
Then the input arguments are provided to the function for the calculations, which returns the results as output arguments. Finally the code in the callback draws the output in an axes object.
Actually, you could create an AXES in the GUI at first and forward its handle to the calculations. Then it could be used from there as: plot(x, y, 'Parent', AxesHandle). But this produces dependencies between the GUI and the calculations. If you avoid such dependencies, it will be much easier to maintain the code or e.g. create a completely new GUI. Then you can call the calculations in a batch process directly also.
Summary: Keep data, calculations and GUI separately. Design them as independent modules. Let the GUI create input data, provide them as inputs for the calculations, get the results as outputs and visualize them in the GUI again. Instead of "connecting", you simply "call" the external function, like you would call any other function.

类别

在 帮助中心 和 File Exchange 中查找有关 Line Plots 的更多信息

编辑:

Jan
2017-12-6

Community Treasure Hunt

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

Start Hunting!

Translated by