matlab - How do I add my own variables to the handles structure from within a custom function of mine? -
i have question ask matlab gurus here ..
so here code (only showing lines of code relevant problem here):
mainprocess(hobject, handles) handles.checkpoint2 =1; guidata(hobject, handles); function testgui1_openingfcn(hobject, eventdata, handles, varargin) handles.output = hobject; handles.checkpoint1 = 1; mainprocess(hobject, handles); handles.checkpoint3 = 1; //edit: checkpoint2 not visible @ line guidata(hobject, handles); handles.checkpoint4 = 1; function saveandcontinuebutton_callback(hobject, eventdata, handles) (breakpoint here) --> facedatabase(handles.currentimageiteration).lookingtowardscamera=handles.lookingatcamera;
so in above code, i'm making these 'checkpoints' @ different parts of code, , seeing of them visible when save , continue button clicked separately ... checkpoint1 created before calling custom function called mainprocess, checkpoint2 created within code of mainprocess, , checkpoint3 created after mainprocess finished executing , control function called it, testgui1_openingfcn ... , checkpoint4 created within testgui1_openingfcn, after handles structure updated in testgui1_openingfcn code ..
so question this, when button clicked , see visible @ point, checkpoint 1 , 3 visible button callback code, checkpoints 2 , 4 not visible ... understand checkpoint4 not visible because created after handles structure updated in testgui1_openingfcn's code ... why checkpoint2 not visible, when @ end of mainprocess's code, did put line:
guidata(hobject, handles);
i mean mainprocess function getting references both hobject , handles, should have write access it, right ?
so why isn't checkpoint2 not visible button's callback code .. ?
any clues ?
edit: tried see if checkpoint2 visible within mainprocess's calling function, right after control returned caller, , there checkpoint2 not visible (see edit in code above) ..
i believe need add following after calling mainprocess()
handles = guidata();
in general, 'handles' struct passed by value guidata() function. therefore, mainprocess() cannot change handles structure -- attach existing structure handle. before making further modifications need (using handles=guidata()), update , set again guidata(h, handles).
let me know if not clear enough (or not work :)
edit
you need change code this:
function testgui1_openingfcn(hobject, eventdata, handles, varargin) handles.output = hobject; handles.checkpoint1 = 1; mainprocess(hobject, handles); handles = guidata(); // <--- new line handles.checkpoint3 = 1; //edit: checkpoint2 visible here guidata(hobject, handles); handles.checkpoint4 = 1; guidata(hobject, handles); // otherwise checkpoint4 not bound hobject
Comments
Post a Comment