Info

此问题已关闭。 请重新打开它进行编辑或回答。

How do I work with the gui?

2 次查看(过去 30 天)
new user 00
new user 00 2018-7-1
关闭: MATLAB Answer Bot 2021-8-20
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!!

回答(2 个)

Sri Harish G
Sri Harish G 2018-7-2
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 个评论
Jan
Jan 2018-7-2
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 2018-7-2
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

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by