From: Matt Fig on 28 May 2010 14:17 There is nothing "proper" about ending subfunctions with an END. There is also nothing improper about ending a subfunction with an END. Neither the main function, nor the subfunctions require an END. For example, type >> edit nchoosek and look at how TMW coded the file. No END statements at the ends of the subfunctions there!
From: Adam on 28 May 2010 14:21 "Steven Lord" <slord(a)mathworks.com> wrote in message <htov5a$aq0$1(a)fred.mathworks.com>... > > "Adam " <abc5(a)ubc.ca> wrote in message > news:htotfe$p06$1(a)fred.mathworks.com... > > Hi, > > > > I'm creating a somewhat complex GUI and will need to pass data to and from > > functions clearly and easily. Because of the complexity of the project, I > > would like to use GUIDE to make the GUI programming simpler. > > > > The issue I'm having is with GUIDE's generated .m file. In the auto > > generated format, functions don't seem to have an end command. > > That's correct. > > > The automatic generated function is open and callbacks also don't end. > > I don't know what you mean by "is open" in this context, but you are not > correct that the callback functions don't end. Any function in a file that > contains a nested function must end with an END, and each such function will > end at its corresponding END; functions in a file that does not contain a > nested function should not end with END, but will end at the start of the > next function or at the end of the file. > > > If I properly end functions, the code doesn't run. > > Off the top of my head, I can't think of anything inherent about the > GUIDE-generated code that would prevent it from running if you made the > functions end with END -- what error message did it give you? > > > I would like to define variables that can be accessed within callbacks. > > For example, one button asks the user to choose a file, while another uses > > the filename to read the file and uses data from within it. Unfortunately, > > because the functions don't end, I can't use global variables. I also > > can't use the handle of the button, since no data is actually stored in a > > button object. I would like to do the same thing with a menu item which > > asks the user to import a file. Is there a simple way to pass data from > > within these endless functions? Is there a better way to do this? > > Read the "Managing and Sharing Application Data in GUIDE" section of the > Creating Graphical User Interfaces documentation. > > http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f5-998197.html > > -- > 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 > What I meant by is open, is simply that it does not end. I'm having numerous errors when ending the callbacks. What happens is, if I end each callback, function varargout also requires a callback. If I end varargout, it runs, but gives a list of errors as shown below (there's more- this is a sample). Essentially, I am ending the Guide Generated Code in this case. ??? Error using ==> feval Undefined function or method 'nContoursBox_CreateFcn' for input arguments of type 'double'. Error in ==> gui_mainfcn at 96 feval(varargin{:}); Error in ==> optip at 26 gui_mainfcn(gui_State, varargin{:}); Error in ==> guidemfile>@(hObject,eventdata)optip('nContoursBox_CreateFcn',hObject,eventdata,guidata(hObject)) ??? Error using ==> struct2handle Error while evaluating uicontrol CreateFcn ??? Error using ==> feval Undefined function or method 'nMaxIterationsBox_CreateFcn' for input arguments of type 'double'. Error in ==> gui_mainfcn at 96 feval(varargin{:}); Error in ==> optip at 26 gui_mainfcn(gui_State, varargin{:}); Error in ==> guidemfile>@(hObject,eventdata)optip('nMaxIterationsBox_CreateFcn',hObject,eventdata,guidata(hObject)) ??? Error using ==> struct2handle Error while evaluating uicontrol CreateFcn ??? Error using ==> feval Undefined function or method 'regAccuracyBox_CreateFcn' for input arguments of type 'double'.
From: Matt Fig on 28 May 2010 14:38 Again, look at previous answers. The functions do not need an END statement to have and end. Put all of this into a single file, save it then call it from the command line with two integer input arguments. function B = func(a,c) % Non-nested functions DO NOT need an END statement. if a>c B = subfunc(a,c); else B = subfunc2(a,c); end function B = subfunc(a,c) B = a + c; function B = subfunc2(a,c) B = a-c;
From: Adam on 28 May 2010 15:40 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <htp2iu$g8g$1(a)fred.mathworks.com>... > Again, look at previous answers. The functions do not need an END statement to have and end. Put all of this into a single file, save it then call it from the command line with two integer input arguments. > > > function B = func(a,c) > % Non-nested functions DO NOT need an END statement. > if a>c > B = subfunc(a,c); > else > B = subfunc2(a,c); > end > > function B = subfunc(a,c) > B = a + c; > > function B = subfunc2(a,c) > B = a-c; Ok thanks, my problem is not so much with the end statements but rather with defining a variable in a subfunction (that happens not to end-it is a callback for a menu item) and using it within another function. I know this can somehow be done using handles but I'm not sure how. Global variables don't work. The behavior I'm looking for is for this menu item to ask the user to choose a file via uigetfile which returns the filename as string. Then use that string in my start button callback to read the file and continue.
From: Paulo on 28 May 2010 16:05 "Adam " <abc5(a)ubc.ca> wrote in message <htp678$77o$1(a)fred.mathworks.com>... > "Matt Fig" <spamanon(a)yahoo.com> wrote in message <htp2iu$g8g$1(a)fred.mathworks.com>... > > Again, look at previous answers. The functions do not need an END statement to have and end. Put all of this into a single file, save it then call it from the command line with two integer input arguments. > > > > > > function B = func(a,c) > > % Non-nested functions DO NOT need an END statement. > > if a>c > > B = subfunc(a,c); > > else > > B = subfunc2(a,c); > > end > > > > function B = subfunc(a,c) > > B = a + c; > > > > function B = subfunc2(a,c) > > B = a-c; > > Ok thanks, my problem is not so much with the end statements but rather with defining a variable in a subfunction (that happens not to end-it is a callback for a menu item) and using it within another function. I know this can somehow be done using handles but I'm not sure how. Global variables don't work. > > The behavior I'm looking for is for this menu item to ask the user to choose a file via uigetfile which returns the filename as string. Then use that string in my start button callback to read the file and continue. In your GUI OpeningFcn do: setappdata(0,'HandleAudioDemo',hObject) That will save the handle for the GUI to your matlab "base". Then you can get the handle in other functions by doing: HandleGUI=getappdata(0,'HandleAudioDemo'); And finally you can save and get data by doing: setappdata(HandleGUI,'MyVariable',4); % to save data to a variable called MyVariable or to get data: MyVariable=getappdata(HandleGUI,'MyVariable'); %to get your variable data to a local variable. Best regards
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Curve / data fit Next: How large was the largest system that you have simulated in Simulink? |