MATLAB Answers

How to open UITable in a new window using an imported text or spreadsheet file

1 view (last 30 days)
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';
app.opts = detectImportOptions(app.InFilePathName,'FileType',FileType,'VariableNamesRange',VariableNamesRange,'Sheet',app.SheetToImportEditField.Value,'PreserveVariableNames',true);
app.CheckFileEditField.Value = 'Improper File';
FileType='text'; %'text';
app.opts = detectImportOptions(app.InFilePathName,'FileType',FileType,'PreserveVariableNames',true);
my_table = readtable(app.InFilePathName,app.opts);
app.UITable.Data = my_table;
%fig = figure;
%uit = handles.UITable;
%newFig = figure();
%copyobj(app.UITable, newFig);
app.WarningLabel.Text = {'*Warning: Incorrect file name format'}; %send this warning if filename does not contain a period.

Accepted Answer

Cris LaPierre
Cris LaPierre on 30 May 2020
Here's some example code that works for me.
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).

More Answers (0)

Community Treasure Hunt

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

Start Hunting!