How to input strings into uitable in app designer
조회 수: 38 (최근 30일)
이전 댓글 표시
I am trying to create a table in an app which the user can add a text comment to. However, whenever I try to change the value of a cell, it displays NaN. I have changed the format of the column to 'char', so I am unsure what the issue is.A and B are random vectors of numbers
C=find(app.B>0.9);
L=length(C);
for i=1:1:L;
app.UITable.Data(i,1)=[i];
end
app.UITable.Data(:,2:3)=0
app.UITable.ColumnFormat(:,2)=({'char'});
app.UITable.ColumnFormat(:,3)=({'char'});
app.UITable.ColumnEditable=[false true true];
Any help would be greatly appreciated!
댓글 수: 3
답변 (1개)
Michael Ashcraft
2022년 4월 25일
I had a similar problem occur while working on my own app. Below is my code with how I solved the issue.
app.UITable.ColumnFormat = {'char','char','numeric','numeric'};
if strcmp(app.VehicleTypeListBox.Value,'(Custom Weight)')
app.UITable.Data{1,1} = 'Custom Weight';
elseif strcmp(app.VehicleTypeListBox.Value,'SUV')
app.UITable.Data{1,1} = 'SUV';
elseif strcmp(app.VehicleTypeListBox.Value,'Pickup Truck')
app.UITable.Data{1,1} = 'Pickup Truck';
else
app.UITable.Data{1,1} = 'Sedan';
end
if strcmp(app.BrakePadMaterialDropDown.Value,'Ceramic')
app.UITable.Data{1,2} = 'Ceramic';
elseif strcmp(app.BrakePadMaterialDropDown.Value,'Semi-Metallic')
app.UITable.Data{1,2} = 'Semi-Metallic';
else
app.UITable.Data{1,2} = 'NAO (Non-Asbestos Organic)';
end
app.UITable.Data{1,3} = num2str(app.InitialSpeedMPHEditField.Value);
app.UITable.Data{1,4} = num2str(distance);
The solution I used make the table read strings also prevented the table from directly reading numbers. However, it is a lot easier to convert numbers into words, than converiing words inti numbers. I strongly encourage paying attention to the curly brackets specifying where the data goes in the table. This will not work if you use parenthesis.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!