2013-02-25 65 views
0

我正在遞歸地調用一個函數,我希望它們都繪製在同一個繪圖中。當我嘗試創建一個處理程序,並與我得到以下錯誤的參數傳遞它:對不同的子功能使用相同的繪圖

??? 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 

您是否知道任何解決方案?我如何繪製一個對象形成我稱之爲的函數?

回答

0

第6行的clf清除了圖形,刪除了要用作圖形輸出的行。

刪除該行,看看它是否工作。

0

嘗試使用hold all。它可以讓你plot圖中的新行沒有清除現有的行。

figure 
hold all 
triangle(...) 

在你的函數裏面調用plot。

plot(x, y) 
plot(x, z) 
相關問題