From: Robert Barrie on 6 Apr 2010 21:49 Hi All, 2 questions, 1 easy, the other requires more reading but is simple at heart (and related to 1) 1. When nesting functions, the nested function have access to workspace variables but when they update them it ISNT reflected in the Workspace (editor). e.g. function xx() dd= 5; yy dd=dd+5; function yy() dd=10; end end ----------------------------- When you step over the call to yy, the dd variable still says 5 in the 'Workspace', step over the next line and the workspace is updated to 15. This is confusing me a little. 2. I am new to building GUI's in ML and rather than just being spoonfed GUIDE I would like to retain control (and therfore understand more) and 'roll my own'. I am using Thomas M's wonderful 'Convert fig to M file' FEX (http://www.mathworks.ch/matlabcentral/fileexchange/14340-convert-fig-to-m) to generate the code for building the controls (without callbacks), which creates the figure and all of the controls (not uitables though) and finishes with: .....build controls.... % Save handles structure guidata(handles.figMain,handles); % Assign function output fig_hdl = handles.figMain; ....end So from my 'main' file, I call this function to 'build' the UI and only add the callbacks I need, but I cant get the callbacks to access my 'handles' variable: function [] = CPMS_main() fig_Hdl = CPMS_build; %call convert-m-to-fig built file handles = guidata(fig_Hdl); set(handles.btnHello, 'Callback', @btnHello_Callback); %------------------------------------------------------------------------- function btnHello_Callback(hObject,eventdata) %HOW DO I ACCESS HANDLES IN HERE? end end Essentially I just wanted to separate the various files (one to build the UI, one to have the callbacks). Ideally I would like to have the numerous callback files, and one main file which pulls them all together but until I work this out I cant go that far. This is more for asthetics(spelling?) and organisation as putting everything in one big file seems dirty to me... TIA, Rob
From: Robert Barrie on 7 Apr 2010 00:40 I may have found the answer to accessing the 'handles' structure when not using GUIDE: In each of my callbacks I just use: handles = guidata(gcf); Being a n00b I am unsure about the performance aspects of this as well as if there would be any problem with multiple figures open etc...
|
Pages: 1 Prev: Urgent....D operator in matlab Next: Pointer Arithmetic and mxSetPr |