# How to interpolate 3D simulation results onto a cartesian grid in Matlab?

**URL:** https://community.freefem.org/t/how-to-interpolate-3d-simulation-results-onto-a-cartesian-grid-in-matlab/2278
**Category:** General Discussion
**Created:** [February 13, 2023, 11:07pm UTC](https://community.freefem.org/t/how-to-interpolate-3d-simulation-results-onto-a-cartesian-grid-in-matlab/2278 "2023-02-13T23:07:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![d2reborn](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/d2reborn/32/1488_2.png) [@d2reborn](https://community.freefem.org/u/d2reborn)
#### Post date: [February 13, 2023, 11:07pm UTC](https://community.freefem.org/t/how-to-interpolate-3d-simulation-results-onto-a-cartesian-grid-in-matlab/2278/1 "2023-02-13T23:07:55Z")

</div>

I think I can use convert\_pde\_data\_3d so no problem now.

=============================================================================

Hi everyone. I am a beginner of Freefem. Now I am computing on a cubic domain and want to plot the solution in Matlab with “ffmatlib”. I am using periodic boundary condition and a periodic fespace.

I wish could interpolate the solution but cannot find a proper function to do this. I also tried to write a script on my own but failed, since I have difficulties understanding the fespace data “Vh” and solution data “u” from “ffsavedata” together with the mesh data.

May I ask if there is such an interpolation function in 3D? Otherwise where can I find information about “ffsavedata”?

Many thanks!

---

<div class="post-metadata">

### Author: ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)
#### Post date: [February 14, 2023, 4:32pm UTC](https://community.freefem.org/t/how-to-interpolate-3d-simulation-results-onto-a-cartesian-grid-in-matlab/2278/2 "2023-02-14T16:32:18Z")

</div>

The interpolation appears to be automatic when accessing with parenthesis. I had a problem  
with using old solution on a new mesh so I wrote a resampler which appears  
to work. It samples the old solution on dof’s for the new mesh. You can see  
that calling A(xp,yp) appears to return “A” at that location. This uses  
kind of a kluge to get x and y suggested by someone else here.  
There may be a better way to do that however.

```auto
macro RESAMPLE( B,Th2,A,Th,E) {
 fespace Ah(Th,E); fespace Bh(Th2,E);
Bh xx=x; Bh yy=y;
for(int i=0; i<xx.n; ++i) {real xp=xx[][i]; real yp=yy[][i];
B[][i]=A(xp,yp); }
} // EOM

```
