简体   繁体   中英

Matlab: how to work with different outputs of function

I've got the function

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

whereas Integrand[1] should be real2 of this function

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

The problem is, if I define the Integrand function before, I get an error, as t is undefined. Do you know how to write real2 as a function in t ?

You could just make a dummy proxy function that only outputs the first argument:

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

Simply define your quick function out of the for loop

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM