Unable to add text to Column/cell of table in AppDesigner.

23 vues (au cours des 30 derniers jours)
Jake Keiper
Jake Keiper le 29 Jan 2021
Modifié(e) : Mario Malic le 29 Jan 2021
I am new to AppDesigner, but I watched many tutorials and went throught the examples. I am attempting to build my first application and I have not been able to troubleshoot this issue. The goal is to have a 5 column table that the user can populate with the relevant information. I Intended the user to be able to add text to the last column as a description or comment to the row. See the picture below. Adding the number of rows works fine, but I have not gotten to Add or Delete or Edit Row yet.
The user can add entries to the five entries, and then click Replace Row and it should populate the row number based on this code (copied from Code View in AppDesigner):
% Button pushed function: ReplaceRowButton
function ReplaceRowButtonPushed(app, event)
% Finding Manually Entered Numbers after Button is pressed
rn = app.RowNumberAddEdit.Value;
t = app.ThicknessEditField.Value;
n = app.nEditField.Value;
k = app.kEditField.Value;
d = app.DescriptionEditField.Value;
app.UITable.Data(rn,2) = t;
app.UITable.Data(rn,3) = n;
app.UITable.Data(rn,4) = k;
app.UITable.Data(rn,5) = d;
end
end
Now, printing variable d in the Command Window gives whatever is typed, for example 'Air', but then it won't add it to the table. I have tried assigning column formatting, using differemt functions, everything results in an error. Anything from NaN, to inserting a random number, to errors like this:
Unable to perform assignment because the size of the left side is 1-by-1
and the size of the right side is 1-by-3.
Error in Table/ReplaceRowButtonPushed (line 59)
app.UITable.Data(rn,5) = d;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 382)
Error while evaluating Button PrivateButtonPushedFcn.
It is clear that I am missing something. Any guidance would be appreciated!

Réponse acceptée

Mario Malic
Mario Malic le 29 Jan 2021
Modifié(e) : Mario Malic le 29 Jan 2021
Hi,
You can edit the table by setting the ColumnEditable property to true. See this link.
The error happens because, the variable type corresponds to the values in the table. If your Description is '0' (numeric), table will not accept the change to the text value.
Also, indexing into table should be done by curly brackets, if you want to replace the content of the cell.
app.UITable.Data(rn,5) % will return a table
app.UITable.Data{rn,5} % will return the the content of table index
app.UITable.Data{rn,5}{1} % will return what's inside of the indexed cell
  2 commentaires
Jake Keiper
Jake Keiper le 29 Jan 2021
Hello,
Thanks for the reply. I tried setting the table to editable and that is done. I have not been able to figure out how to change the variable type to a string instead of numeric. Also, I get the following error based on your indexing suggestion:
"Unable to perform assignment because brace indexing is not supported for variables of this type."
Mario Malic
Mario Malic le 29 Jan 2021
Here's an example,
thickness = zeros(5,1);
realVals = zeros(5,1);
imagVals = zeros(5,1);
descVals = {''; ''; ''; ''; ''}; % cell array of characters
t = table(thickness, realVals, imagVals, descVals);
uiFig = uifigure;
uiTable = uitable('Parent',uiFig);
uiTable.Data = t;
uiTable.ColumnEditable = true;
uiTable.Data{1,4}{1} = 'Text';
% ^ curly to get the content of the table, which is cell
% ^ to get contents of cell, use another curly brackets

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by