How to input strings into uitable in app designer

37 vues (au cours des 30 derniers jours)
Angela Sita
Angela Sita le 5 Fév 2018
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 commentaires
Angela Sita
Angela Sita le 5 Fév 2018
B is a property within the app
Nicolas Leclerc
Nicolas Leclerc le 3 Juin 2020
I have the same problem, have you find a solution ?

Connectez-vous pour commenter.

Réponses (1)

Michael Ashcraft
Michael Ashcraft le 25 Avr 2022
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.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by