嵌套函数并在MATLAB中生成绘图

时间:2016-04-23 15:30:02

标签: matlab signal-processing

我想将给定波束形成器w的空间响应绘制为具有数组响应theta的源的方向a(theta)的函数,即

function y = spat_response(w,Delta,theta_range)

请注意,这是|y(t)|=|w^{H}a(theta)|给出的,w^{H}表示w的复共轭转置。

对于a(theta),我已经拥有:

function a = gen_a(M,Delta,theta)
    for m=1:M
        a(m)=exp(1i*2*pi*Delta*sin(theta)*(m-1));
    end
end

为了绘制空间响应|y(t)|,我没有成功,这是我到目前为止所做的:

function y = spat_response(w,Delta,theta_range)
y(t) = abs(w'*a(theta_range));
a = gen_a(M,Delta,theta);
            function a = gen_a(M,Delta;theta)
                for m=1:M
                    a(m)=exp(1i*2*pi*Delta*sin(theta)*(m-1));
                end    
            end
fplot(y,[-25,25])        
end

嵌套不起作用

1 个答案:

答案 0 :(得分:1)

您不需要嵌套功能。

function y = spat_response(w,Delta,theta_range)
  a = gen_a(M,Delta,theta);
  y(t) = abs(w'*a(theta_range));        
  fplot(y,[-25,25])        
end

function a = gen_a(M,Delta,theta)
    for m=1:M
        a(m)=exp(1i*2*pi*Delta*sin(theta)*(m-1));
    end
end

您只能在spat_response()之外拨打.m,其他功能只能在.m范围内使用