I am trying to return a function handle from a function. The code is shown below:
function drawHandle = drawXYZ(XYZ,drawHandle);
drawHandle = plot3(XYZ(1,:), XYZ(2,:), XYZ(3,:));
set (drawHandle, 'XData',XYZ(1,:),'YData', XYZ(2,:),'Zdata', XYZ(3,:));
I first enter the function with an empty drawHandle (drawXYZ(XYZ,). When the line drawHandle = plot3... I get the error that drawHandle is a double and Matlab can's assign a function handle to a double. If I just replace drawHandle with a new variable x the assignment works correctly but still won't allow me to assign drawHandle to x. The function is called from a simulink function block but I don't see why that would make any difference. Any suggestions would be greatly appreciated.
Yours works fine for me in Matlab, but maybe from simulink it is different and the type of a variable cannot be changed.  is of type double, so assigning a handle to it requires a type change of the variable, which it may not like.
Thanks for the idea. I think it would work as looking at the documentation, sometime recently MatLab changed graphics objects from double to objects. Unfortunately the call is in a simulink function and when I tried I get gobjects(0) not supported for code generation. I'm thinking that I need to do this in a mask for the function which I've been avoiding since I can't figure out the documentation about masks. I tried to use the initialization part of a mask to initialize a bunch of points to draw but wasn't able to get the function to recognize the code in the mask initializaton section. Let me know if you have any other suggestions about how to figure out masks. In the mean time I'll work on understanding masks.