Azzera filtri
Azzera filtri

App Designer table won't populate or auto-update

11 visualizzazioni (ultimi 30 giorni)
Tyler Reohr
Tyler Reohr il 24 Ago 2023
Commentato: Voss il 25 Ago 2023
Hello all!
This is my first time using the app designer. In general I make codes and am familiar with the way that I did so, and I just work in the .m file. Recently however, I've undertaken a few projects that will require other people to interact with my code, most of which have no coding experience at all, let alone with Matlab, so I've decided to make an application instead of my traditional way of doing it.
I'm essentially creating a database for building keys, and the overall code is very simple, but I'm having trouble with the display. Because the excel I'm storing the info in when the app is not open doesn't populate changes until it is re-opened, I want to have a table within the app display all of the information that is there, but I'm having trouble getting that data to display, even in its original state called in the startup function. Beyond that, I would also like it to auto update, but I believe once I figure out how to populate the table I should be able to do that relatively simply. I'm not getting any errors with my code, but the table remains completely blank.
Attachments:
Table that should be populated with data, but is blank:
My startup function code:
clc;
app.fullFileName= fullfile(app.folder,app.baseFileName);
if ~exist(app.folder,'dir')
mkdir(app.folder);
end
if ~exist(app.fullFileName,"file")
writematrix(app.infoDesc,app.fullFileName,'Range','A1:D1');
end
app.prevKeyData = readmatrix(app.fullFileName,"OutputType","string", "FileType","spreadsheet",TreatAsMissing="",ExpectedNumVariables=4);
app.prevKeyDataTab = readtable(app.fullFileName,VariableNamingRule='preserve',TreatAsMissing='');
app.infoDesctab = {"Serial Number","Door(s) Accessible","Number of Existing Keys","Room Owner(s)"};
app.prevKeyDataTab = app.prevKeyDataTab(2:size(app.prevKeyDataTab),app.spaceHolder);
app.UITable.Data = app.prevKeyDataTab;
If it's necessary for troubleshooting, I can also attach the .mlapp file I'm working with, but didn't know if that was customary to do with App Designer requests, so I've elected to leave it off the original post.
Thanks in advance for any help! As I said, this is the first time I've used this, so it could very well be a really dumb mistake, but I haven't been able to figure it out for the last hour or so.

Risposte (1)

Voss
Voss il 24 Ago 2023
Modificato: Voss il 24 Ago 2023
Assuming the Excel file doesn't already exist, you do this:
writematrix(app.infoDesc,app.fullFileName,'Range','A1:D1');
Range is one row, so only one row is written to file, even if app.infoDesc contains more than one row.
  • If the range you specify is smaller than the size of the input data, then the writing function writes only a subset of the input data that fits into the range.
Then, you read the file into a table variable:
app.prevKeyDataTab = readtable(app.fullFileName,VariableNamingRule='preserve',TreatAsMissing='');
and keep (some columns of) rows 2 through the end of it:
app.prevKeyDataTab = app.prevKeyDataTab(2:size(app.prevKeyDataTab),app.spaceHolder);
But the table variable app.prevKeyDataTab only had one row initially (when it was created by readtable), so now (after keeping only rows 2 through end) it will have zero rows.
Then app.UITable is populated with app.prevKeyDataTab, which is empty, so the uitable is empty.
  8 Commenti
Voss
Voss il 25 Ago 2023
Titles are stored separately from data in a table, so you don't need to cut the titles off.
Voss
Voss il 25 Ago 2023
I don't see how the size() issue can explain what the problem was. t(2:size(t),:) is the same as t(2:size(t,1),:) is the same as t(2:end,:). And notice that the table had 2 rows after that, but zero columns (size 2-by-0). So I suspect the problem was actually that app.spaceHolder was empty before but is not now.

Accedi per commentare.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by