I have a Matlab GUI code that lets you draw on axes and passes the coordinates to a constant in Simulink. While the mouse button is held down it should draw on the axes and send the coordinates and when it'not, it should send the coordinates but it should not draw. Here is the code:
`

```
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
    % hObject    handle to figure1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    global bool;
    bool=false;
    set(handles.figure1,'WindowButtonMotionFcn',@(hObject,eventdata)figure1_WindowButtonMotionFcn(hObject,eventdata,guidata(hObject)));
    %set the WindownButtonMotionFcn back in order to make it work again

function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
    set(handles.figure1,'WindowButtonMotionFcn',@empty); %change the windowbuttonmotionfcn in order not to let it 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 over figure - except title and menu.
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
    coord=get(handles.axes4,'CurrentPoint');
    set_param('dosya_yukle_deneme/Constant','value',num2str(coord(1))); 

```

While the mouse button is pressed down, it draws the lines but the set\_param function doesn't work. However, the one in the figure1\_WindowButtonMotionFcn works pretty well when needed. It seems like the problem is the while loop. Any help would be appreciated.