Unable to add text to Column/cell of table in AppDesigner.
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jake Keiper
el 29 de En. de 2021
Editada: Mario Malic
el 29 de En. de 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!
0 comentarios
Respuesta aceptada
Mario Malic
el 29 de En. de 2021
Editada: Mario Malic
el 29 de En. de 2021
Hi,
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 comentarios
Mario Malic
el 29 de En. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!