【问题标题】:Matlab: how to work with different outputs of functionMatlab:如何处理函数的不同输出
【发布时间】:2013-04-02 10:18:03
【问题描述】:

我有这个功能

function [imag2] = sumIntegral(x,w,a,b,c,p)
    imag2 = zeros(p-1,p);
for k = 1:p-1
    f = @(t)(1:p-1==k)*Integrand[1](t,x,w,a,b,c);
    imag2(k,:) = quadv(f,x(k),x(k+1));
end

Integrand[1] 应该是这个函数的real2

[real2,real3,imag2,imag3] = Integrand(t,x,w,a,b,c,p);

问题是,如果我之前定义了Integrand 函数,我会得到一个错误,因为t 是未定义的。你知道如何将real2写成t中的函数吗?

【问题讨论】:

  • 您介意更好地说明您的问题并以更清晰的方式提出吗?提前致谢。
  • 感谢您到目前为止的快速回答。我想知道的是如何访问 real2 作为 t 中的函数。我想声明 [real2,real3,imag2,imag3] = Integrand(t,x,w,a,b,c,p);首先然后写 f = @(t)(1:p-1==k)*real2,但我总是得到错误,即 t 未定义

标签: matlab function output


【解决方案1】:

简单地定义你的快速函数在for循环之外

function [imag2] = sumIntegral(x,w,a,b,c,p)
    imag2 = zeros(p-1,p);
    f = @(t)(1:p-1==k)*Integrand[1](t,x,w,a,b,c);
    for k = 1:p-1        
    imag2(k,:) = quadv(f,x(k),x(k+1));
    end
end

【讨论】:

    【解决方案2】:

    你可以创建一个只输出第一个参数的虚拟代理函数:

    function real2 = MyIntergrand(t,x,w,a,b,c)
        real2 = Integrand(t,x,w,a,b,c);
    end
    

    【讨论】:

      猜你喜欢
      • 2015-11-30
      • 1970-01-01
      • 2017-11-27
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多