0

I have a popupmenu using the uicontrol class within matlab. However, the numbers that are greater than 1 million are expressed in scientific notation:

That just looks weird

This is generated using the following code:

sPropGrid = uiextras.Grid('Parent', staticPropPanel);
...
self.nSamplesEdit = uicontrol('Style', 'popupmenu', 'Parent', sPropGrid, ...
                'String', {[256 16384 32768 65536 131072 262144 524288 1048576 2097152 16252928]});

I would like to stop this, and display the entire number in normal formatting. How do I do this?

James Mertz
  • 8,459
  • 11
  • 60
  • 87
  • Note: I've tagged this as [tag:matlab-guide] however I'm not specifically using GUIDE everywhere. My main GUI is developed using the GUI Layout Toolbox. However this specific issue is related to the MatLab object `uicontrol`. – James Mertz Jun 13 '13 at 16:24

1 Answers1

2

imple example of :

f=figure;
L=uicontrol('parent',f,'style','popupmenu','string',{'1','2','6000000'});

Isn't showing this behaviour.

What code is generating these values? As popupmenu uses a cell array of strings to represent its value, it is likely that the code generating the GUI is using

sprintf('%0.5g',value);

Or something along those lines to input values to the popupmenu. If you change this to

sprintf('%d',value); 

or

sprintf('%.0f',value);

for floating point values (although number of samples should be an integer, I imagine), it should have the behaviour you want.

Edit:

Addition to answer your extra info.

To use sprintf to format as you wish using a numerical array, you can use this syntax for arbitrary array X:

arrayfun(@(x) {sprintf('%d',x)},X);

So in your popupmenu you can use:

self.nSamplesEdit = uicontrol('Style', 'popupmenu', 'Parent', sPropGrid, ...
    'String', arrayfun(@(x) {sprintf('%d',x)},...
    [256 16384 32768 65536 131072 262144 524288 1048576 2097152 16252928]));
Hugh Nolan
  • 2,508
  • 13
  • 15