How to open UITable in a new window using an imported text or spreadsheet file
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Forrest Ward
am 29 Mai 2020
Kommentiert: Forrest Ward
am 1 Jun. 2020
I want to open a uitable using an imported file with app designer. The file will be imported using a button, followed by a few different commands to determine what kind of file it is, followed by a 'readtable' command to actually import the table along with any user defined specifications (opts). I want to the uitable to be opened in a new window because there is too much data to display on the front of my app. I have tried serval different methods to do this but have had no success. I'm copying my code for the function when the button is pushed (which is the most relevant to this). I apologize for not commenting out my code very well.
% Button pushed function: SelectFileButton
function SelectFileButtonPushed(app, event)
app.CheckFileEditField.Value = ' ';
app.WarningLabel.Text = ' ';
if contains(app.InFilePathName, '.') %checking for period('.') in filename.
index = strfind(app.InFilePathName,'.');
FileExtension = app.InFilePathName(index(end)+1:end);
ValidSpreadsheetExtensions={'xlsx', 'xls', 'xlsm', 'xlsb', 'xltx', 'xltm','ods'};
if ismember(FileExtension,ValidSpreadsheetExtensions)
app.CheckFileEditField.Value = 'Proper File';
FileType = 'spreadsheet';
VariableNamesRange=strcat('A',num2str(app.NumHeaderLinesEditField.Value+1));
app.opts = detectImportOptions(app.InFilePathName,'FileType',FileType,'VariableNamesRange',VariableNamesRange,'Sheet',app.SheetToImportEditField.Value,'PreserveVariableNames',true);
else
app.CheckFileEditField.Value = 'Improper File';
FileType='text'; %'text';
app.opts = detectImportOptions(app.InFilePathName,'FileType',FileType,'PreserveVariableNames',true);
end
my_table = readtable(app.InFilePathName,app.opts);
app.UITable.Data = my_table;
%fig = figure;
%uit = handles.UITable;
%uit(fig);
%newFig = figure();
%copyobj(app.UITable, newFig);
else
app.WarningLabel.Text = {'*Warning: Incorrect file name format'}; %send this warning if filename does not contain a period.
end
end
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 30 Mai 2020
Here's some example code that works for me.
vals=readtable("datafile.csv");
fig = uifigure;
uit = uitable(fig,'Data',vals);
uit.Position = [0 0 500 400];
You can control aspects of the table's appearance by modifying table properties (colum width, column headers, etc).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!