user interface - matlab set_param function doesn't work in loop -


i have matlab gui code lets draw on axes , passes coordinates constant in simulink. while mouse button held down should draw on axes , send coordinates , when it'not, should send coordinates should not draw. here code: `

function figure1_windowbuttonupfcn(hobject, eventdata, handles)     % hobject    handle figure1 (see gcbo)     % eventdata  reserved - defined in future version of matlab     % handles    structure handles , user data (see guidata)     global bool;     bool=false;     set(handles.figure1,'windowbuttonmotionfcn',@(hobject,eventdata)figure1_windowbuttonmotionfcn(hobject,eventdata,guidata(hobject)));     %set windownbuttonmotionfcn in order make work again    function figure1_windowbuttondownfcn(hobject, eventdata, handles)     set(handles.figure1,'windowbuttonmotionfcn',@empty); %change windowbuttonmotionfcn in order not let work     global bool;     bool=true;     global lastx;     global lasty;     x=0;     while bool         coord=get(handles.axes4,'currentpoint');         if coord(1)<0.003             coord(1)=0.003             x=0;         end         if coord(1)>1             coord(1)=1             x=0;         end         if coord(3)<0             coord(3)=0             x=0;         end         if coord(3)>0.95            coord(3)=0.95            x=0;         end         if x>1            arrayx=[lastx coord(1)];            arrayy=[lasty coord(3)];            line(arrayx,arrayy);            set_param('dosya_yukle_deneme/constant','value',num2str(coord(1)));         end         x=x+1;         lastx=coord(1);         lasty=coord(3);         drawnow;     end  function empty(~,~,~)  % --- executes on mouse motion on figure - except title , menu. function figure1_windowbuttonmotionfcn(hobject, eventdata, handles)     coord=get(handles.axes4,'currentpoint');     set_param('dosya_yukle_deneme/constant','value',num2str(coord(1)));  

while mouse button pressed down, draws lines set_param function doesn't work. however, 1 in figure1_windowbuttonmotionfcn works pretty when needed. seems problem while loop. appreciated.

you can't run while loop within figure1_windowbuttondownfcn callback because matlab gui single-threaded. means while loop blocking matlab gui , preventing things updating correctly. need let callback return in order matlab able update gui. general rule gui callbacks in matlab; whatever in callback block gui.

in fact don't need while loop @ all, because windowbuttonmotionfcn call every time cursor changes. put code inside loop figure1_windowbuttonmotionfcn callback. need global flag indicating whether button down or not, easy create. figure1_windowbuttondownfcn should set button down flag, , figure1_windowbuttonupfcn resets button down flag. figure1_windowbuttonmotionfcn checks whether button down flag set, , if is, executes code within while loop.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -