我正在递归调用一个函数,我希望它们都绘制在同一个图中。当我尝试创建一个处理程序并使用参数传递它时,我收到以下错误:
??? Error using ==> set Invalid handle object.
Error in ==> triangle at 23
set(h, 'xdata', [x1,x3], 'ydata', [y1,y3]);
在调用我的函数之前,我创建了一个处理程序并设置了我的首选项:
h = plot([0,1],[0,0]);
set(h, 'erasemode', 'none');
triangle(0,0,1,0,10,0,h)
这是我的功能:
function triangle(x1,y1,x2,y2, deepth , n,h)
%Paints a equilateral triangle for two given Points
if depth > n
shg
clf reset
%vector
v_12 = [x2-x1;y2-y1];
%rotate vector
g_uz = [0.5,-sqrt(3)/2;sqrt(3)/2, 0.5];
p = g_uz * v_12;
x3 = p(1) + x1;
y3 = p(2) + y1;
axis([-10 10 -10 10]);
axis off
drawnow
set(h, 'xdata', [x1,x3], 'ydata', [y1,y3]);
drawnow
set(h, 'xdata', [x2,x3], 'ydata', [y2,y3]);
drawnow
v_13 = [x3-x1,y3-y1];
v_23 = [x3-x2,y3-y2];
% 1-3 triangle
triangle(x1+v_13(1)/3,y1 + v_13(1)/3, x1+ 2*v_13(1)/3,y1 + 2*v_13(1)/3, tiefe, n+1 );
end
你知道有什么解决办法吗?如何以对象形式绘制我调用的函数?