App Designer - Struggling to fill out UITable and define variables

23 views (last 30 days)
Hi, I'm working on my first ever app and there is a learning curve I wasn't expecting. I have a pretty simple app.
  1. User inputs group name and QR code and TXID, says if it passed or failed, and why it failed.
  2. Some of this data gets displayed to a table that the user can edit if they did something wrong
  3. User moves on to the next one
  4. When they are done, they press done and a spreadsheet will be made with all the data they input in the formatting I want.
It looks like this (some potentially proprietary information removed):
So, I can't get anything to display to the table (Num is the counter in the upper left that goes up if you press "Next TXID"). When it tries to put the count in the table I get the error: Error setting property 'Data' of class 'Table':Data must be a numeric, logical, string, cell, or table array.
The counter variable is app.Count, and when I try to store data into arrays for future use (e.g. TXID(app.Count.Value) = app.TXIDEditField.Value then it says the two sides are incompatible.
I'm not sure what code to include here that is most helpful, but here are the most relevant functions:
% Value changed function: TXIDEditField
function TXIDEditFieldValueChanged(app, event)
app.UITable.Data.Num(app.Count.Value) = app.Count.Value; %add count # to table
app.UITable.Data.TXID(app.Count.Value) = upper(app.TXIDEditField.Value); %input TXID into table
drawnow();
end
% Button pushed function: NextTXIDButton
function NextTXIDButtonPushed(app, event)
%when the next button is pushed, store all data in variables for
%use in the spreadsheet later
%pass/fail
if app.PassButton.Value == true
deploymentPASSFAIL(app.Count.Value) = 'Pass';
else
deploymentPASSFAIL(app.Count.Value) = 'Fail';
end
deploymentFAILUREMODE(app.Count.Value) = app.FailureModeListBox.Value; %failure mode
%if the table is not already filled in, fill it in with the
%proper information
app.UITable.Data.PassFail(app.Count.Value) = deploymentPASSFAIL(app.Count.Value); %pass/fail
app.UITable.Data.FailureMode(app.Count.Value) = deploymentFAILUREMODE(app.Count.Value); %failure mode
%when the "next txid" button is pushed, clear all the values
%and increase the counter by 1
app.Count.Value = app.Count.Value + 1;
app.QRCodeEditField.Value = '';
app.TXIDEditField.Value = '';
app.PassButton.Value = true;
app.FailButton.Value = false;
app.FailureModeListBox.Value = 'N/A';
drawnow();
end

Accepted Answer

Amanda Beatty
Amanda Beatty on 31 Mar 2020
I ended up figuring out a way to do populate each individual cell of my UITable.
  1. I had to predefine the UITable as empty cells
  2. Using the notation of app.UITable.Data.ColumnName(Count)=Value was not working. I took off the column name and defined both the row and column number.
  3. Input a value of type cell into it.
% Value changed function: TXIDEditField
function TXIDEditFieldValueChanged(app, event)
%predefine UITable
if app.Count.Value == 1 %only do this once, when the counter = 1
app.UITable.Data = {[], '', '', ''};
else
end
%populate UITable column 1 and 2
app.UITable.Data(app.Count.Value, 1) = num2cell(app.Count.Value); %Counter
app.UITable.Data(app.Count.Value, 2) = cellstr(convertCharsToStrings(app.UITable.Data(app.TXIDEditField.Value)); %TXID value, from character to string to cell
drawnow();
end

More Answers (1)

Harsha Priya Daggubati
Harsha Priya Daggubati on 27 Mar 2020
Edited: Harsha Priya Daggubati on 27 Mar 2020
Hi,
It would be better if you can attach all the error messages you face when the above code is executed. You can make use of breakpoints in MATLAB and debug through the code. I can only sense type mismatch, you can use 'class' to determine the type of data you are trying to insert into the table. I hope you will be able to solve your issue with the above mentioned suggestions.
This might be of help:

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!