Matlab 如何格式化uicontrol的字符串以不使用科学符号?
我有一个Matlab 如何格式化uicontrol的字符串以不使用科学符号?,matlab,user-interface,matlab-guide,Matlab,User Interface,Matlab Guide,我有一个弹出菜单,使用matlab中的uicontrol类。但是,大于100万的数字用科学符号表示: 这是使用以下代码生成的: sPropGrid = uiextras.Grid('Parent', staticPropPanel); ... self.nSamplesEdit = uicontrol('Style', 'popupmenu', 'Parent', sPropGrid, ... 'String', {[256 16384 32768 65536
弹出菜单
,使用matlab中的uicontrol
类。但是,大于100万的数字用科学符号表示:
这是使用以下代码生成的:
sPropGrid = uiextras.Grid('Parent', staticPropPanel);
...
self.nSamplesEdit = uicontrol('Style', 'popupmenu', 'Parent', sPropGrid, ...
'String', {[256 16384 32768 65536 131072 262144 524288 1048576 2097152 16252928]});
我想停止此操作,并以正常格式显示整个数字。如何做到这一点?简单的例子是:
f=figure;
L=uicontrol('parent',f,'style','popupmenu','string',{'1','2','6000000'});
没有表现出这种行为
生成这些值的代码是什么?由于popupmenu使用字符串单元格数组来表示其值,因此生成GUI的代码可能正在使用
sprintf('%0.5g',value);
或者沿着这些线向弹出菜单输入值。如果你把这个改成
sprintf('%d',value);
或
对于浮点值(尽管我认为样本数应该是整数),它应该具有您想要的行为
编辑:
除了回答你的额外信息
要使用sprintf使用数字数组进行格式化,可以对任意数组X使用以下语法:
arrayfun(@(x) {sprintf('%d',x)},X);
因此,在弹出菜单中,您可以使用:
self.nSamplesEdit = uicontrol('Style', 'popupmenu', 'Parent', sPropGrid, ...
'String', arrayfun(@(x) {sprintf('%d',x)},...
[256 16384 32768 65536 131072 262144 524288 1048576 2097152 16252928]));
注意:我已将其标记为,但我并不是在任何地方都特别使用指南。我的主GUI是使用GUI布局工具箱开发的。但是,此特定问题与MatLab对象uicontrol
有关。
self.nSamplesEdit = uicontrol('Style', 'popupmenu', 'Parent', sPropGrid, ...
'String', arrayfun(@(x) {sprintf('%d',x)},...
[256 16384 32768 65536 131072 262144 524288 1048576 2097152 16252928]));