I sounds like "myev3"' is being defined outside of the scope of the function. If "myev3" is defined in the MATLAB base workspace, it will not be accessible from the function workspace.
You can pass "myev3" into the function instead:
myev3 = legoev3('usb')
myfunc(myev3)
function myfunc (mylego)
beep(mylego)
end
You can refer to the following links for more information about working with function workspaces.
https://www.mathworks.com/help/matlab/matlab_prog/share-data-between-workspaces.html