Effacer les filtres
Effacer les filtres

How to convert a string to int

691 vues (au cours des 30 derniers jours)
Nu9
Nu9 le 6 Oct 2011
hi
in my script i got this
function [] = N_call(src,evendata)
% Callback for secondary GUI editbox.
S = get(0,'userdata');
%set(S.ed2,'string',get(gcbo,'string')) % Set gui_passdata editbox string.
str13=get(src,'string');
if (isempty(str2num(str13)))
set(src,'String','0')
else
n=str13;
save n
set(S.ed13,'string',get(gcbo,'string')) % Set gui_passdata editbox string.
end
and it saves to workspace as a string i guess, it shows value='20' max-nothing min-nothing
and i've another function that need to use the value but like an int. for an example if i define a=2 in script it shows value=2 max=2 and min=2, and this is waht i want but i don't know how
i've tried to use str2num and double with no results
  2 commentaires
Sean de Wolski
Sean de Wolski le 6 Oct 2011
str2double(get(src,'string')) doesn't work?
Nu9
Nu9 le 7 Oct 2011
i've tried that but still the same,it saves as a char/string

Connectez-vous pour commenter.

Réponse acceptée

Laura Proctor
Laura Proctor le 6 Oct 2011
The command
save n
will save all the variables in your function workspace to a file named n.mat. Is this what you intend?
If you do wish to save str13 in the variable n as an integer, this command will work:
n = str2num(['uint8(',str13,')']);
  4 commentaires
Nu9
Nu9 le 7 Oct 2011
it returned the same as before :/
Walter Roberson
Walter Roberson le 7 Oct 2011
n = str2double(str13);

Connectez-vous pour commenter.

Plus de réponses (2)

York Dau
York Dau le 4 Avr 2020
k

York Dau
York Dau le 4 Avr 2020
5

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by