Hi, I have uitable and edit box. If I write 0.10000002 into edit box, than in uitable I get 0.10000002....this is ok. But if I write 0.00000002, than I get 0.00000002....but how can I get it in form 2.0*10^(-8)???
Thank you.
This is my code:
UserData.celkovamatica=cell(2,2);
for i=1:2
for j=1:2
UserData.celkovamatica{i,j}='0';
end
end
UserData.celkovamatica{1,1}=sscanf(get(handles.edit6,'string'), '%s');
T2=cellstr(char(UserData.celkovamatica{1,1}));
result=strcat('<HTML>',T2);
t = uitable('Parent',f,'Data',result)

 Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de En. de 2014

1 voto

Your code
sscanf(get(handles.edit6,'string'), '%s')
has the same effect as
get(handles.edit6, 'string')
unless the contents of the edit box have multiple parts separated by spaces (in which case your code pulls out only the first one.)
In order to get 2.0*10^(-8) you would need to convert to numeric form and then convert the numeric form to string using a different format.
If you convert to numeric form and store numbers into UserData.celkovamatica instead of strings, then you could set ColumnFormat to 'short g' to get 2e-08 as the output.
If that is not acceptable, then you will need to store strings (like you do now) and format it yourself, such as
s = sprintf( '%.1e', str2double(get(handles.edit6,'string')));
and then do string manipulation on the '2.0e-08' that results
UserData.celkovamatica{1,1} = regexp(s, {'e', '$'}, {'*10^(', ')'})

3 comentarios

john
john el 15 de En. de 2014
Hi Mr.
I got this error:
??? Error using ==> regexp
Additional arguments to regexp must be numeric or strings.
Error in ==> Simulator>pushbutton4_Callback at 1238
UserData.celkovamatica{1,1} = regexp(s, {'e', '$'}, {'*10^(', ')'})
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Simulator at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)Simulator('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
What can I do?
Walter Roberson
Walter Roberson el 15 de En. de 2014
Make it regexprep() instead of regexp()
john
john el 15 de En. de 2014
OK, thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 13 de En. de 2014

Comentada:

el 15 de En. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by