How can I save a string from a uicontrol edit box into a a part of my structure ?

3 ビュー (過去 30 日間)
Adrien
Adrien 2014 年 8 月 4 日
コメント済み: Adrien 2014 年 9 月 1 日
Hello,
I working on a Programmatic GUI. I have an editbox wich allow the user to enter a string. What I want is to save it into the GUI and not only into the callback function. My edtibox and the file into I want to save the string are in a Structure.
S.f = figure('Position', [500,150,1000,700], ...
'name', 'GUI2');
S.eT_name = uicontrol( 'Style', 'edit', ...
'Position', [400,100,200,50], ...
'FontSize', 15, ...
'BackgroundColor', 'white');
S.s_name = [];
function [] = eT_name_callback(varargin)
S = varargin{3};
s_Name = get(varargin{1}, 'String');
display(s_Name);
S.s_name = s_Name;
display(S.s_name);
But the problem is, he is saving it only local. The second way I've tryed it, was with set. But it didn't worked also. I think it was because of a format file ... How can I solve it. One other question. Are set and get only for uicontrol or can i use it also to set a string into a variable that I created ?
Thank you in advance

採用された回答

Sara
Sara 2014 年 8 月 4 日
You have to put your string into the handles structure as
handles.s_Name = s_Name;
and then save it with:
guidata(hObject, handles); % put this at the end of the callback
You can then use your string anywhere else in your gui as handles.s_Name
  1 件のコメント
Adrien
Adrien 2014 年 9 月 1 日
But is handle a special call ? I thought I can define what my handle is. So I'm giving to the function a handle called S. It's my structure array. But if I'm doing this it didn't worked :
S.f = figure('Position', [400,400,1000,400], ...
'Name', 'Store data');
S.eT_name = uicontrol( 'Style', 'edit', ...
'Position', [400,100,200,50], ...
'FontSize', 15, ...
'BackgroundColor', 'white');
S.pB_save = uicontrol( 'Style', 'pushbutton', ...
'String', 'Save', ...
'Position', [700,75,200,50], ...
'FontSize', 20, ...
'BackgroundColor', 'red');
set(S.pB_save, 'Callback', {@pB_save_callback, S});
set(S.eT_name, 'Callback', {@eT_name_callback, S});
function [] = eT_name_callback(hObject, eventdata, S)
s_Name = get(hObject, 'String');
S.s_name = s_Name;
guidata(hObject, S);
function [] = pB_save_callback(hObject, eventdata, S)
display(S.s_Name);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by