# Multiply two griddedInterpolant functions

조회 수: 3(최근 30일)
Anita Capelli 2021년 10월 25일
편집: Anita Capelli 2021년 10월 25일
I have some data and I have interpolated them using the function griddedInterpolant. Now, let's suppose I end up with f and g from the previous interpolation. What I want to do now is fun = f*g. I can I do that?
Thanks
Anita

댓글을 달려면 로그인하십시오.

### 채택된 답변

Bjorn Gustavsson 2021년 10월 25일
If you have 2 functions f(x,y) and g(x,y) you can evaluate the product on your selected grid-points and multiply them:
fx_at_xy = f(x,y).*g(x,y);
or you can create a function that multiplies the two:
f_times_g = @(x,y) f(x,y).*g(x,y);
and use that one - this should (at least ought to) be more convenient when for example integrate over some region in the x-y-plane.
HTH
##### 댓글 수: 1표시숨기기 없음
Anita Capelli 2021년 10월 25일
편집: Anita Capelli 2021년 10월 25일
I couldn't do it like this. So I changed and I used instead of griddedInterpolant interp1 creating an handle function. Therefore, supposing to have data_x = [], data_y = [], I created f = @(x) interp1(data_x,data_y,x). The same for g. How should I multiply them? I was doing
h = @(x) f(x).*g(x)
but it says Array indices must be positive integers or logical values.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!