Is it possible to control the precision of a numeric value displayed in a UITABLE in MATLAB 7.6 (R2008a)?

17 views (last 30 days)
I am currently using the the list of available formats, given in the FORMAT function in MATLAB, to select the precision of a numeric value in a UITABLE. However, I would like to have more control over the format. For example, I want to control the number of digits displayed before and after the decimal point.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 May 2017
The ability to control the precision of a number in UITABLE, besides using the FORMAT function, is not available in MATLAB.
To work around this issue, one can use the SPRINTF function to control the precision of the numeric value displayed. As an example, consider the following code:
 
f = figure('Position',[100 100 400 150]);
dat = {6.125, 456.3457, true, 'Fixed';...
6.75, 510.2342, false, 'Adjustable';...
7, 658.2, false, 'Fixed';};
columnname = {'Rate', 'Amount', 'Available', 'Fixed/Adj'};
columnformat = {'numeric', 'bank', [], {'Fixed' 'Adjustable'}};
columneditable = [false false true true];
t = uitable('Units','normalized','Position',...
[0.1 0.1 0.9 0.9], 'Data', dat,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable);
data = get(t, 'data');
for i = 1:numel(data)
if(isnumeric(data{i}))
tempStr = sprintf('%2.4g', data{i});
data{i} = tempStr;
end
end
set(t, 'data', data);
This creates a UITABLE and allows the user to control the precision of the numeric value using the SPRINTF function.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!