How to open UITable in a new window using an imported text or spreadsheet file
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Forrest Ward
il 29 Mag 2020
Commentato: Forrest Ward
il 1 Giu 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 Commenti
Risposta accettata
Cris LaPierre
il 30 Mag 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).
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!