Set decimal place for uitable

조회 수: 54 (최근 30일)
Adi Purwandana
Adi Purwandana 2024년 11월 12일 15:53
편집: Pavl M. 2024년 11월 13일 6:54
Hello there,
I have a mat table and I want to present one of the column of such table (the data column) in one decimal place of scientific format in UIFIGURE table (example: 0.00001 should be 1.0e-5). But, my code so far present it as 0.0000. Please find attached the data.
load('data_decimal.mat');
uitable(uifigure,'Data',results{:,:},'ColumnName',results.Properties.VariableNames); % this line gives 0.0000
Thanks!

채택된 답변

Star Strider
Star Strider 2024년 11월 12일 16:27
It may be necessary to create a string variablee or character array to get what you want, because MATLAB will use full precision if it has all the numbers available to it.
LD = load('data_decimal.mat');
results = LD.results
results = 6x2 table
x data ______ __________ 123.94 3.8848e-09 123.87 4.8751e-09 123.79 4.7731e-07 123.8 8.6742e-09 123.79 1.6945e-08 123.79 1.9707e-07
expstr = @(x) [x(:).*10.^ceil(-log10(abs(x(:)))) floor(log10(abs(x(:))))];
results.data1 = compose('%.1fe%d', expstr(results.data))
results = 6x3 table
x data data1 ______ __________ __________ 123.94 3.8848e-09 {'3.9e-9'} 123.87 4.8751e-09 {'4.9e-9'} 123.79 4.7731e-07 {'4.8e-7'} 123.8 8.6742e-09 {'8.7e-9'} 123.79 1.6945e-08 {'1.7e-8'} 123.79 1.9707e-07 {'2.0e-7'}
datamtx = expstr(results.data);
format shortG % <— This Is Probably Necessary
results.data2 = round(datamtx(:,1),1) .* 10.^datamtx(:,2)
results = 6x4 table
x data data1 data2 ______ __________ __________ _______ 123.94 3.8848e-09 {'3.9e-9'} 3.9e-09 123.87 4.8751e-09 {'4.9e-9'} 4.9e-09 123.79 4.7731e-07 {'4.8e-7'} 4.8e-07 123.8 8.6742e-09 {'8.7e-9'} 8.7e-09 123.79 1.6945e-08 {'1.7e-8'} 1.7e-08 123.79 1.9707e-07 {'2.0e-7'} 2e-07
This is the best I can do with your data.
.
  댓글 수: 2
Adi Purwandana
Adi Purwandana 2024년 11월 12일 16:31
Aha! Great, thank you @Star Strider!
Star Strider
Star Strider 2024년 11월 12일 16:33
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Cris LaPierre
Cris LaPierre 2024년 11월 12일 16:10
Set the column display format to 'shortE' (you can see other options here)
fig = uifigure;
uit = uitable(fig,"Data",randi(100,10,3));
uit.Data(1,1) = 0.00001
uit.ColumnFormat = {'shortE'}
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2024년 11월 12일 18:56
Specify a format for each column
uit.ColumnFormat = {[],'shortE'}
Adi Purwandana
Adi Purwandana 2024년 11월 12일 22:50

댓글을 달려면 로그인하십시오.


Pavl M.
Pavl M. 2024년 11월 12일 16:09
Select any format your wish:
%in older Matlab versions format('shortE')
load( 'data_decimal.mat' );
uitable(uifigure, 'Data' ,round(results{:,:},1), 'ColumnName' ,results.Properties.VariableNames); %
%or
format('shortE')
load( 'data_decimal.mat' );
uitable(uifigure, 'Data' ,fix(results{:,:}*10)/10, 'ColumnName' ,results.Properties.VariableNames); %
  댓글 수: 2
Adi Purwandana
Adi Purwandana 2024년 11월 12일 16:20
This codes round everything. That's not what I want. I need to keep the first column as it is and change the second column in scientific format.
Pavl M.
Pavl M. 2024년 11월 13일 6:53
편집: Pavl M. 2024년 11월 13일 6:54
Right, you are as usual of course right Adi.
  1. Have you found how to re-format per column (each column in different format, for example x column in standard numeric, and data column in short scientific?
Because so far they proposed format for whole table, right?:
uit=uitable(uifigure, 'Data' ,results{:,:}, 'ColumnName' ,results.Properties.VariableNames);
uit.ColumnFormat = { 'shortE' };
Whether compose and string pre-printing with C style formating, like '%.1fe%d' and than putting formatted strings to the ui table works better in your specific case than formatting each column by specifiying as per 'shortE'?
Of course in real world and in real time all comes not ideal, while optimality can be achieved with patience and hard work.
Analysis:
How can we add more value to your project and posts, can we make it for CNC, 3D printer machines (also to combine with your previous question on specific distances between 2 tables, like distance for CNC Hybdrid manufacturing, Swiss-type Lathe machining and another distance metric for logistics industries)? For example to find some more simple machining by specially preprocessed tables run instead of complex code?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by