Unable to add text to Column/cell of table in AppDesigner.
조회 수: 17 (최근 30일)
이전 댓글 표시
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/503838/image.png)
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
채택된 답변
Mario Malic
2021년 1월 29일
편집: Mario Malic
2021년 1월 29일
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
Mario Malic
2021년 1월 29일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!