matlab中function和end问题,错误提示This statement is not inside any function. (6行代码)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab中function和end问题,错误提示This statement is not inside any function. (6行代码)相关的知识,希望对你有一定的参考价值。

function RC = reflect_coeff( ZL,Z0,f )
RC = 0.5*abs(ZL-Z0)/sqrt(ZL*Z0)*abs(cos(f*pi/2));
end

x=0:0.1:5;
a=reflect_coeff(100,50,x);
plot(x,a,'b-')
------------------------------------------------------------------------
>> micro_a
Error: File: micro_a.m Line: 5 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function
"reflect_coeff".)

参考技术A 可以单独保存1-3行代码后在命令行中运行5-7行代码或改为
function reflect_coeff
x=0:0.1:5;
a=reflect_coeff1(100,50,x);
plot(x,a,'b-')

function RC = reflect_coeff1( ZL,Z0,f )
RC = 0.5*abs(ZL-Z0)/sqrt(ZL*Z0)*abs(cos(f*pi/2));本回答被提问者和网友采纳
参考技术B end不需要

以上是关于matlab中function和end问题,错误提示This statement is not inside any function. (6行代码)的主要内容,如果未能解决你的问题,请参考以下文章