簡體   English   中英

無法訪問Matlab函數輸出-變量未定義

[英]Cannot access matlab function output - variable undefined

我正在嘗試使用等式curve = (1/(sqrt(2*pi*s.^2))* exp(-((tempAnomaly-m).^2)/(2*s.^2))); 我將程序分為兩個函數,但是從主函數調用計算函數時,即使它是輸出值,我似乎也無法訪問“曲線”變量。 我在第4行( plot(tempAnomaly, curve); )上收到錯誤“未定義的函數或變量”。

有關如何訪問此變量的任何提示,以便我能夠對其進行繪制將非常有用。 謝謝!

function TempAnomaly()
tempAnomaly = linspace(-5, 5, 1000);
normalDist(0.4, 0.1, tempAnomaly)
plot(tempAnomaly, curve);
end

function curve = normalDist(m, s, tempAnomaly)
curve = (1/(sqrt(2*pi*s.^2))* exp(-((tempAnomaly-m).^2)/(2*s.^2)));
end

normalDist輸出應與第4行中的curve相等。因此,在第4行中未定義curve

function TempAnomaly()
    tempAnomaly = linspace(-5, 5, 1000);
    curve = normalDist(0.4, 0.1, tempAnomaly) %%% <- correct this line
    plot(tempAnomaly, curve);
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM