matlab - Implementation of GUIDE GUI buttons -
i have question implementation of buttons inside guide framework. have 2 buttons created , drop down menu not seen in below code (referenced in numc line). way program meant run select drop down menu, generate button takes directly drop down menu. third button, optimize, needs numc variable , cities matrix. possible reference them directly in optimize function, or first have use output feature in generate button make 2 usable. numc easy enough recapture using same line in generate, need cities matrix it's generated.
function optimize_callback(hobject, eventdata, handles) % hobject handle optimize (see gcbo) % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) % --- executes on button press in generate. function generate_callback(hobject, eventdata, handles) % hobject handle generate (see gcbo) % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) numc = get(handles.numcities, 'value'); numc = numc*10; cities = rand(numc,2); cla %clears current window plot(cities(1:numc,1),cities(1:numc,2),'r') hold on plot(cities(1:numc,1),cities(1:numc,2),'*')
you can use guidata command save data handles structure , make available other function. note how in above code, comment handles reads structure handles , user data (see guidata). can this
% --- executes on button press in generate. function generate_callback(hobject, eventdata, handles) % hobject handle generate (see gcbo) % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) % etc. have above % save data handles.numc = numc; handles.cities = numc; guidata(hobject,handles);
in body of optimize_callback function, numc , cities should directly accessible handles handles.numc , handles.cities respectively.
Comments
Post a Comment