How to input strings into uitable in app designer
Show older comments
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 Comments
Birdman
on 5 Feb 2018
What is app.B? does this code work in a button callback?
Angela Sita
on 5 Feb 2018
Nicolas Leclerc
on 3 Jun 2020
I have the same problem, have you find a solution ?
Answers (1)
Michael Ashcraft
on 25 Apr 2022
0 votes
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.

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!