MATLAB: How to right-justify numeric cells in a UITABLE while avoiding scientific notation in MATLAB 7.9 (R2009b)

MATLAB

I would like to be able to right-justify UITABLE numbers such as 0.00001, 0.00065, etc. in this exact format. However, MATLAB converts these numbers to 1.0000e-05, 6.5000e-04, etc. when displaying them in a UITABLE.

Best Answer

This functionality cannot be directly implemented in MATLAB 7.9 (R2009b).
As a workaround, you can use SPRINTF to format these numbers as desired. However, strings are left-justified by default in UITABLE cells, therefore you will have to specify the desired string width in the SPRINTF format argument.
The following example shows how to produce right-justified strings with a default width of 10 characters as well as displaying the numbers in a non-scientific notation in a UITABLE:
% Numeric data
data={0.001; 0.00045; 0.0000238}
[h,w]=size(data);
data=data(:);
out=repmat({''},1,h*w);
for i=1:h*w
width=abs(length(num2str(data{i}))-2);
form=['%10.' num2str(width) 'f']; % width of 10
out{i}=sprintf(form,data{i});
end
out=reshape(out,[h w]);
% Make a GUI table object with "fixedwidth" font
uitable('data',out,'fontname','fixedwidth')