Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How do I work with the gui?

2 visualizzazioni (ultimi 30 giorni)
new user 00
new user 00 il 1 Lug 2018
Chiuso: MATLAB Answer Bot il 20 Ago 2021
I have to prepare a gui where i should call an excel file using a browsing push button and use its data for further calculation. This file will basically have two rows, but I'm not aware of the number of elements in the table.So I was thinking if I can retrieve the data and store it in two arrays. But I'm totally new to gui and don't know how to do it. So, can someone help? Thanks in advance!!

Risposte (2)

Sri Harish G
Sri Harish G il 2 Lug 2018
You can use the uibutton function to create a push button. You can then edit the ButtonPushedFcn Property of the push button to call a function that will look through the files and open the selected excel file as a table.
b=uibutton('Text','Browse','ButtonPushedFcn','browse_click()');
You can then define the browse_click function as:
function browse_click()
[selectedFile,pathName]=uigetfile({'*.xlsx;*.xlsm;*.xls;*.xltm;*.xltx','Excel Files (*.xlsx,*.xlsm,*.xls,*.xltm,*.xltx)'});
cd(pathName(1:end-1));
tab=readtable(selectedFile);
assignin('base','tab',tab);
end
This will save the selected Excel File as a table in variable tab in the base workspace.
  1 Commento
Jan
Jan il 2 Lug 2018
Changing the current folder is a source of bugs. Prefer using absolute path names:
tab = readtable(fullfile(pathname, selectedFile));
Instead of creating variables in the base workspace, it is more secure to store them in the current figure, e.g. in the UserData or ApplicationData of any UI element.

Jan
Jan il 2 Lug 2018
You can create a GUI by GUIDE, AppDesigner or programmatically. For the latter you find the excellent 41 GUI examples. For the other two tools, you find an exhaustive documentation, see https://www.mathworks.com/discovery/matlab-gui.html

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by