Integrate the output of interpol
1 view (last 30 days)
Show older comments
Hello everybody ! This is my code where Mz_seg is a 4D matrix. I would like to integrate it over x and y. However, I have an error :
" Error using griddedInterpolant/parenReference. Query coordinates input arrays must have the same size.
Error in testdebit>@(x,y,z,t)Interpol4D(x,y,z,t) (line 30). MaFonction4D=@(x,y,z,t) Interpol4D(x,y,z,t);
Error in testdebit>@(x,y)MaFonction4D(x,y,13,9) (line 32). NewFunction=@(x,y) MaFonction4D(x,y,13,9);
Error in integral2Calc>integral2t/tensor (line 228). Z = FUN(X,Y); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55). [Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9). [q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106). Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in testdebit (line 34). debit=integral2(NewFunction,60,73,97,110);"
Do you know how to procede ?
N=size(Mz_seg);
xn=[1:N(1)];
yn=[1:N(2)];
zn=[1:N(3)];
tn=[1:N(4)];
[X, Y, Z, T]=ndgrid(xn,yn,zn,tn);
Interpol4D=griddedInterpolant(X,Y,Z,T,Mz_seg);
MaFonction4D=@(x,y,z,t) Interpol4D(x,y,z,t);
NewFunction=@(x,y) MaFonction4D(x,y,13,9);
debit=integral2(NewFunction,60,73,97,110);
0 Comments
Answers (1)
Walter Roberson
on 17 May 2021
If you have a numeric array that you want to integrate, then you would use trapz() one time for each dimension to integrate over.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!