Info
This question is closed. Reopen it to edit or answer.
How do I work with the gui?
2 views (last 30 days)
Show older comments
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!!
0 Comments
Answers (2)
Sri Harish G
on 2 Jul 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 Comment
Jan
on 2 Jul 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
on 2 Jul 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
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!