How to format the decimal/integer number in the cells of a table in the App Designer code?

19 Ansichten (letzte 30 Tage)
I am biulding an n x 3 matrix as the data for a table created in an App Designer script. The table contents are numeric values that all display with four decimal places. I would like the first column to be displayed as an integer (no digits after the decimal place). The numerical values in the first column is the sequence of index values from j=1:n. The assignment of j values to the matrix is Data(j,1)=j inside the j=1:n loop. I changed this to Data(j,1)=int8(j) and the values were displayed in the table as integers but so were the numbers in the second and third columns which I wanted to remain with four decimal places displayed. The values in those columns were assigned after the loop by using this code:
Data(:,2)=transpose(t(1,:));
Data(:,3)=transpose(tdiff(1,:));
I would like only the first column to be displayed as integer and the second and third columns displayed with four decimal places.

Antworten (1)

Animesh Gupta
Animesh Gupta am 29 Aug. 2022
It is my understanding that you want the first column to be of "integer" data type and the remaining second and third column of "double" data type.
I tried to replicate the procedure that you mentioned, but I am not able to produce the exact result.
Following is the script I used -
n = 5;
data = rand(n,3)*10
data = 5×3
1.6708 5.4530 7.3443 6.5843 8.8441 1.8031 6.9719 3.4817 9.4661 2.9044 2.5481 4.4644 0.8774 2.8227 8.9379
for j = 1:n
data(j,1) = int8(j);
end
data
data = 5×3
1.0000 5.4530 7.3443 2.0000 8.8441 1.8031 3.0000 3.4817 9.4661 4.0000 2.5481 4.4644 5.0000 2.8227 8.9379
Thus, the output is not the same as in the description.
Please note that the data type of the first column will remain "double" because it is a matrix and a matrix has singular data type.
Although the first column is of double data type, it can still be used as an index column due to implicit type casting.
index = data(3,1);
data(index,:)
ans = 1×3
3.0000 3.4817 9.4661
I hope it helps.

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by