How do I get the integer value from a edit box?

The only way I know of getting the value of an edit box is getting it as a string. How do I assign it as an integer. My edit box input is '123'. How do I retrieve it and store and an integer. I tried the code below but it didnt work
widthBox=get(handles.edit5,'String');
ws = str2num(widthBox);

 Respuesta aceptada

Image Analyst
Image Analyst el 2 de Abr. de 2016

1 voto

Looks like it should work. Why do you say it doesn't?

3 comentarios

I get the error
Error using str2num (line 32)
Requires string or character array input.
widthBox contains 123 which is taken from the editbox in my GUI.
widthBox =
'123'
Recap
Recap el 2 de Abr. de 2016
Its ok now, im using str2double and it seems to do the job.
perhaps it's a cell, which might happen if you have the max property set to bigger than 1. So try to use char() or cell2mat() to cast it to a character.
editBoxContents = get(handles.edit5,'String');
ws = str2double(char(editBoxContents));
% or
ws = str2double(cell2mat(editBoxContents));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Abr. de 2016

Comentada:

el 2 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by