Calculating a convolution using conv vs. a loop

7 views (last 30 days)
Hi,
I'm currently calculating the convolution of a Gaussian and a power law using the following code snippet:
for j=1:1:size(Axis_Tw,1)
t = Axis_Tw(j);
if Axis_Tw(j) <= 100
temp = 0;
CPara = 0;
for i=1:1:nt+1
CPara = CPara + Gas(temp,Gparams)*PowerLaw(t-temp,Eparams)*dt;
temp = temp + dt;
end
FPara(j) = CPara;
else
FPara(j) = PowerLaw(t,Eparams);
end
end
I'm trying to use conv to do this instead of a loop. I'm confused on how to do this. Can conv take functions as arguments or can I only use vectors? I've tried evaluating Gas and PowerLaw for Axis_Tw and then passing those arrays into conv, but the result is very different (as in several hundred orders of magnitude).
Thanks, Charles

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!