Clear Filters
Clear Filters

Matlab GUI file reading and plotting graph

26 views (last 30 days)
Hi
I am new to the Matlab and want to make GUI for my code. It is a simple task for the calculation of slope of striaght line. "y=mx+c"
' y ' values are in excel file(1st column)
' x ' values are the row numbers in excel file.
What i require from GUI is mentioned below.
1- "Browse" button to take excel "xls or xlsx" file from path and read the values inside of that file( y values).
2-"RUN" button to execute the code(code for calculating slope) and make a graph.
Please if some one can guide according to these requirments.

Answers (1)

Agnish Dutta
Agnish Dutta on 11 Feb 2019
Edited: Agnish Dutta on 11 Feb 2019
MATLAB App designer can be used to create GUIs with interactive elements such as buttons, text sections, plots etc. By programming the callback functions of these interactive elements, you can get desired results. To open it, type appdesigner on the MATLAB terminal.
Procede with the following to create a GUI with the specifications you have asked for:
  • To add a button, simply drag one from the component library and place it at any desired location on the UIFigure object created by default. You can change any property of a component by modifying the values in the component properties section. To change the name of a button, modify the Text property.
  • Add a Callback function (which can be done by right-clicking the component in consideration and selecting Callbacks) of the browse button to be able to load the contents of a .XLXS file from a browse window. Use the following command in the Callback function to do this.
pathToFile = uigetfile('*.xlsx');
  • The 'uigetfile()' function returns the path to the file (as a string) selected on the browser window. This can be used to read the contents of the file as a table in matlab using the 'readtable()' function. The columns of the table can be accesed individually.
  • Add UIAxes and another Button component to your UIFigure. Modify the Text property of this new button to "Plot". Add a Callback function to this new button to calculate and display the required plot on the UIAxes component. This can be done via adding the following command to the Callback function:
plot(app.UIAxes, table_data.(1), table_data.(2));
(Here 'table_data' is the variable that contains the data from the XLXS file as a table variable).
Relevant links:
  1. MATLAB App Designer - https://in.mathworks.com/help/matlab/ref/appdesigner.html?searchHighlight=Appdesigner&s_tid=doc_srchtitle
  2. Writing Callback functions - https://in.mathworks.com/help/matlab/creating_guis/write-callbacks-for-gui-in-app-designer.html
  3. Opening file selection dialogue box - https://in.mathworks.com/help/matlab/ref/uigetfile.html
  4. Creating GUI plots using UIAxes - https://in.mathworks.com/help/matlab/ref/uiaxes.html?searchHighlight=UIAxes&s_tid=doc_srchtitle
  5. Buttons - https://in.mathworks.com/help/matlab/ref/matlab.ui.control.button-properties.html?searchHighlight=Button&s_tid=doc_srchtitle

Community Treasure Hunt

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

Start Hunting!