How to input strings into uitable in app designer
Mostrar comentarios más antiguos
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 comentarios
Birdman
el 5 de Feb. de 2018
What is app.B? does this code work in a button callback?
Angela Sita
el 5 de Feb. de 2018
Nicolas Leclerc
el 3 de Jun. de 2020
I have the same problem, have you find a solution ?
Respuestas (1)
Michael Ashcraft
el 25 de Abr. de 2022
0 votos
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.

Categorías
Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!