我有3個短的函數,我在Matlab裏面用3個獨立的m文件編寫。從另一個函數內部調用一個函數?
主函數稱爲F_並接受一個輸入參數並返回一個包含3個元素的向量。
從F_輸出的元素1和2(應該是)使用其他2 m個文件中的函數進行計算,現在讓我們稱它們爲theta0_和theta1_。
下面的代碼:
function Output = F_(t)
global RhoRF SigmaRF
Output = zeros(3,1);
Output(1) = theta0(t);
Output(2) = theta1(t) - RhoRF(2,3)*sqrt(SigmaRF(2,2))*sqrt(SigmaRF(3,3));
Output(3) = -0.5*SigmaRF(3,3);
end
和
function Output = theta0_(t)
global df0dt a0 f0 SigmaRF
Output = df0dt(t) + a0 + f0(t) + SigmaRF(1,1)/(2*a0)*(1-exp(-2*a0*t));
end
和
function Output = theta1_(t)
global df1dt a1 f1 SigmaRF
Output = df1dt(t) + a1 + f1(t) + SigmaRF(2,2)/(2*a1)*(1-exp(-2*a1*t));
end
我創建的句柄這些功能如下:
F = @F_;
theta0 = @theta0_;
theta1 = @theta1_;
當我運行F_通過它與t
任何價值,我得到以下錯誤處理:
F_(1)
Undefined function 'theta0' for input arguments of type 'double'.
Error in F_ (line 9)
Output(1) = theta0(t);
請協助。我在這裏做錯了什麼?
我只希望能夠從另一個內部調用一個函數。
您將其定義爲'theta0_'並稱之爲'theta0'。另外,您不需要通過處理來調用它。 – Oleg