how can i get data from an Excel to app designer EDITFIELDS wit example folder and file
이전 댓글 표시
how can i get data from an Excel to app designer EDITFIELDS wit example folder and file
댓글 수: 2
m.montaser sabry
2025년 7월 17일
답변 (1개)
Govind KM
2025년 7월 17일
I assume you wish to read data from an Excel file, and display it in "EditField" components in MATLAB App Designer. This can be achieved by using the "readtable" function to read data from the specified Excel file within the code for your App, on App startup or in the callback for some other component.
For example, you could add an "EditField" and a "Button" to your app, with the "ButtonPushed" callback reading data from the Excel file and displaying the desired value in the "EditField" component. Here is sample code for such a callback:
function ButtonPushed(app, event)
filename = fullfile(pwd, 'mydata.xlsx'); % Specify path to the Excel file
data = readtable(filename); % Read the data from the Excel file
% Set the desired value for the Edit Field from the Excel file data
% Here the Edit Field value is set as the first element from the Name
% column
app.EditField.Value = string(data.Name(1));
end
Additional features could be included with this, such as using "uigetfile" to allow the user to select the Excel file instead of specifying the path in the App code, or adding components such as Sliders or Dropdowns to let the User select which data from the Excel file would be displayed in the Edit Field.
Kindly refer to the following documentation link for more information on the "readtable" function: https://www.mathworks.com/help/matlab/ref/readtable.html
Hope this helps!
댓글 수: 12
m.montaser sabry
2025년 7월 17일
m.montaser sabry
2025년 7월 17일
Walter Roberson
2025년 7월 17일
It gives only one row because the posted code specifically does
app.EditField.Value = string(data.Name(1));
To get all entries you would use
app.EditField.Value = string(data.Name);
m.montaser sabry
2025년 7월 17일
Walter Roberson
2025년 7월 17일
Use
app.EditField.Value = string(data.(COLUMN_NUMBER));
for example
app.EditField.Value = string(data.(2));
if the data is in column 2.
However, if the column is already text then use
app.EditField.Value = data.(COLUMN_NUMBER);
m.montaser sabry
2025년 7월 17일
Walter Roberson
2025년 7월 18일
When you use readtable() each column gets assigned a variable name. If one of the first few lines of the input file looks like a list of headers then the headers are assigned as variable names; otherwise numbered variable names beginning with 'Var' are used (such as 'Var1').
When the syntax .(COLUMN_NUMBER) is used that accesses columns by index, regardless of the variable name associated with the column.
m.montaser sabry
2025년 7월 18일
m.montaser sabry
2025년 7월 18일
Walter Roberson
2025년 7월 18일
excelfilepath=‘D:\mirror1\mirror1.xlsx’;
data=readtable(excelfilepath);
value=data{1,:};
appEditField.Value=string(value);
or
excelfilepath=‘D:\mirror1\mirror1.xlsx’;
data=readtable(excelfilepath);
value=data.(1);
appEditField.Value=string(value);
m.montaser sabry
2025년 7월 18일
m.montaser sabry
2025년 7월 19일
편집: Stephen23
2025년 7월 19일
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!