Prev: Realised variance with microstructure noise
Next: How to import & separate two sets of from a single .txt file?
From: Stefan Heinen on 29 May 2010 18:59 Hey, My first time building a GUI in matlab. And I'm trying to get input i my program. Doing this like: function meanfunction hinput = uicontrol('Style','edit','String',''... ,'Position',[1470,550,120,25],'Callback',{@input_Callback}); function input_Callback(source,eventdata) str = get(source, 'String'); nr = str2num(str); list = nr(1:10); end function pushbuton_Callback(source,eventdata,list) listMed = mean(list) end end error ??? Input argument "list" is undefined. I like to use the created list future on but I havend figurt out jet how I can use it in the next function. So when i push the button, the programme uses list. Thx, Stefan
From: Matt Fig on 29 May 2010 19:26 Put this in after your uicontrol creation. list = []; Then get rid of list as an input argument to the pushbutton callback.
From: Stefan Heinen on 29 May 2010 19:58 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hts7qd$35l$1(a)fred.mathworks.com>... > Put this in after your uicontrol creation. > > list = []; > > Then get rid of list as an input argument to the pushbutton callback. That didn't really work. I did: function mean f = figure('Visible','off','Position',[50,50,1600,900]); hinput = uicontrol('Style','edit','String','','Position',... [1470,550,120,25],'Callback',{@input_Callback}); list = []; function [pain, painMed] = input_Callback(source,eventdata) str = get(source, 'String'); nr = str2num(str); list = nr(1:10); end function finalbutton_Callback(source,eventdata) mean(list) end output is than NaN. Course after input the list is still empty.. list = [] so that didn't really work. But thx for trying. Stefan
From: Stefan Heinen on 29 May 2010 20:15 I didn't change anything but t works fine now. Thx
From: Steven Lord on 1 Jun 2010 12:02
"Stefan Heinen" <s.g.h.heinen(a)live.com> wrote in message news:hts9md$cs$1(a)fred.mathworks.com... > "Matt Fig" <spamanon(a)yahoo.com> wrote in message > <hts7qd$35l$1(a)fred.mathworks.com>... >> Put this in after your uicontrol creation. >> >> list = []; >> >> Then get rid of list as an input argument to the pushbutton callback. > > That didn't really work. > > I did: > > function mean So you're calling your GUI function mean but expecting (I assume) your finalbutton_Callback to compute the average value in the vector list using the built-in MEAN function? That won't work. Rename your GUI function to something like meanGUI. function meanGUI > > f = figure('Visible','off','Position',[50,50,1600,900]); > > hinput = uicontrol('Style','edit','String','','Position',... > [1470,550,120,25],'Callback',{@input_Callback}); > list = []; > > function [pain, painMed] = input_Callback(source,eventdata) > str = get(source, 'String'); > nr = str2num(str); > list = nr(1:10); > end > > function finalbutton_Callback(source,eventdata) > mean(list) > end If both input_Callback and finalbutton_Callback are nested functions that are nested inside your main GUI function meanGUI, then this would work ... if you had something in the GUI that actually invoked your finalbutton_Callback. function [M, list] = meanGUI f = figure('Position',[50,50,1600,900]); hinput = uicontrol('Style','edit','String','','Position',... [1470,550,120,25],'Callback',{@input_Callback}); list = []; M = []; uicontrol('Style', 'pushbutton', 'String', 'Push to close', ... 'Position', [1470 500 120 25], 'Callback', @finalbutton_Callback); uiwait(f); function [pain, painMed] = input_Callback(source,eventdata) str = get(source, 'String'); nr = str2num(str); list = nr(1:10); end function finalbutton_Callback(source,eventdata) M = mean(list); close(gcbf); end end -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com |