How to format the decimal/integer number in the cells of a table in the App Designer code?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Animesh Gupta
el 29 de Ag. de 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
for j = 1:n
data(j,1) = int8(j);
end
data
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,:)
I hope it helps.
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!