필터 지우기
필터 지우기

How to convert a string to int

조회 수: 691 (최근 30일)
Nu9
Nu9 2011년 10월 6일
답변: York Dau 2020년 4월 4일
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
Sean de Wolski
Sean de Wolski 2011년 10월 6일
str2double(get(src,'string')) doesn't work?
Nu9
Nu9 2011년 10월 7일
i've tried that but still the same,it saves as a char/string

댓글을 달려면 로그인하십시오.

채택된 답변

Laura Proctor
Laura Proctor 2011년 10월 6일
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
Nu9
Nu9 2011년 10월 7일
it returned the same as before :/
Walter Roberson
Walter Roberson 2011년 10월 7일
n = str2double(str13);

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

York Dau
York Dau 2020년 4월 4일
k

York Dau
York Dau 2020년 4월 4일
5

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by