I'm trying to plot a curve using the equation curve = (1/(sqrt(2*pi*s.^2))* exp(-((tempAnomaly-m).^2)/(2*s.^2)));
. I have my program split into two functions, but when calling the calculating function from the main function, I can't seem to access the 'curve' variable even though it is the output value. I am getting the error "Undefined function or variable" on line 4 (plot(tempAnomaly, curve);
).
我试图使用方程曲线绘制曲线=(1 /(sqrt(2 * pi * s。^ 2))* exp( - ((tempAnomaly-m)。^ 2)/(2 * s。^ 2)));.我的程序分为两个函数,但是当从main函数调用计算函数时,我似乎无法访问'curve'变量,即使它是输出值。我在第4行得到错误“Undefined function or variable”(plot(tempAnomaly,curve);)。
Any tips on how to access this variable so I'm able to plot it would be great. Thanks!
有关如何访问此变量以便我能够绘制它的任何提示都会很棒。谢谢!
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
1 个解决方案
#1
1
Output of normalDist
should be equal to curve
in line 4. So curve
is undefined in line 4
normalDist的输出应该等于第4行中的曲线。因此,第4行中的曲线未定义
function TempAnomaly()
tempAnomaly = linspace(-5, 5, 1000);
curve = normalDist(0.4, 0.1, tempAnomaly) %%% <- correct this line
plot(tempAnomaly, curve);
end
#1
1
Output of normalDist
should be equal to curve
in line 4. So curve
is undefined in line 4
normalDist的输出应该等于第4行中的曲线。因此,第4行中的曲线未定义
function TempAnomaly()
tempAnomaly = linspace(-5, 5, 1000);
curve = normalDist(0.4, 0.1, tempAnomaly) %%% <- correct this line
plot(tempAnomaly, curve);
end