Mixed data types in a Table

36 views (last 30 days)
Pappu Murthy
Pappu Murthy on 28 May 2020
Commented: Pappu Murthy on 7 Jul 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.

Accepted Answer

Bhargavi Maganuru
Bhargavi Maganuru on 7 Jul 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 Comment
Pappu Murthy
Pappu Murthy on 7 Jul 2020
Thanks for the workaround. Pappu Murthy.

Sign in to comment.

More Answers (0)

Categories

Find more on Tables 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!