Mixed data types in a Table

37 vues (au cours des 30 derniers jours)
Pappu Murthy
Pappu Murthy le 28 Mai 2020
Commenté : Pappu Murthy le 7 Juil 2020
I have an app developed using app Designer.
I have a table with 5 rows and 3 columns. These are usually double type and my numbers show up with 4 digits after the decimal point.
However, on the 5th row all 3 columns I like to be treated as integers. for e.g. Insted of [5.0000 25.0000 100.0000] I would like to display them as just [5 25 100].
my code for this part is like app.UITable.Data(5,:) = FD; where FD is a row vector with values 2 25 100 all integer*8 type.
Thanks in advance for any help.

Réponse acceptée

Bhargavi Maganuru
Bhargavi Maganuru le 7 Juil 2020
If you are entering values into table using array, you cannot change the values of the last row from double to int as data type of the elements should be same in the arrays.
As a workaround, you can use cell array to store data into table and then change the datatype of the rows as shown in the following code snippet.
app.UITable.Data = {23.34,1.343,343.2;5.0000, 25.0000, 100.0000};
app.UITable.Data(2,:)=num2cell(int8(cell2mat(app.UITable.Data(2,:))));
  1 commentaire
Pappu Murthy
Pappu Murthy le 7 Juil 2020
Thanks for the workaround. Pappu Murthy.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables 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