How to format the decimal/integer number in the cells of a table in the App Designer code?
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Animesh Gupta
2022-8-29
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!