Using interp2 for several functions

I am using interp2 in the way shown below(Only two lines to demonstrate what i mean). However. I have many lines of code with only the function (f1,f2..fn)changing. Is there a way of being able to produce these outputed matrices more efficently? and if so can they be seperated or do they have to be in one large matrix?
test = interp2(x,y,f1,xq,yq);
test2 = interp2(x,y,f2,xq,yq);

댓글 수: 3

Stephen23
Stephen23 2021년 3월 25일
Use a simple loop. Storing the data in arrays will make this a lot easier (compared to numbered variables).
I have now stored all of the fucntions into a 3d matrix as shown below. It runs but the output is the same dimensions as test and test2 above, rather than being 3d . I think it shows the mean values which is not what I need . If test gives a 12x12 matrix, then I would like for "main" to be 12x12xn, where n is the number of functions I have . Sorry if this isnt the clearest explanation
Fmatrix = cat(3,f,f2,f2,f3...fn)
for i = [1:1:n]
main = interp2(x,y,squeeze(Fmatrix(:,:,i)),xq,yq);
end
Matt J
Matt J 2021년 3월 25일
Are the query points xq,yq gridded or scattered?

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

답변 (1개)

Matt J
Matt J 2021년 3월 25일
편집: Matt J 2021년 3월 25일

0 개 추천

fCell = {f1,f2,...,fn};
n=numel(fCell);
G=griddedInterpolant({y,x},fCell{1});
test=cell(1,n);
for i=1:n
G.Values=fCell{i};
test{i}=G(yq,xq);
end

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2021년 3월 25일

댓글:

2021년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by