フィルターのクリア

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 Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by