returning an object handle from a function
조회 수: 18 (최근 30일)
이전 댓글 표시
I am trying to return a function handle from a function. The code is shown below:
function drawHandle = drawXYZ(XYZ,drawHandle);
if isempty(drawHandle)
drawHandle = plot3(XYZ(1,:), XYZ(2,:), XYZ(3,:));
axis([-5,+5,-5,+5,-5,+5])
else
set (drawHandle, 'XData',XYZ(1,:),'YData', XYZ(2,:),'Zdata', XYZ(3,:));
end
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.
Thanks,
Andy Cruce
댓글 수: 0
답변 (3개)
Walter Roberson
2019년 8월 5일
Graphics objects cannot be Simulink signals, not unless that changed in r2019a.
You can double() a graphics object handle to get the old style numeric handle. You might need to handle() the double to use it for graphics.
댓글 수: 0
Adam
2019년 8월 5일
편집: Adam
2019년 8월 5일
Try passing in
gobjects(0)
instead.
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!