7

I'm strugling to convert some MATLAB code into Julia. I have some 3D gridded data (temperature that varies bi-dimensionally and over time) and want to change from a (x,y,t) mesh to a more loose (xi,yi,ti) mesh. In MATLAB it would be a simple interp(x,y,t,T,xi,yi,ti).

I tried using Interpolations, Dierckx, but both seemed to work only over 2D gridded data. Am I getting something wrong? I'm quite new in Julia programing...

I'm already considering the possibility of solving the problem via PyCall with some NumPy/SciPy funtion.

Thanks!

  • Welcome to Stack Overflow! Please read [ask]. This reads as a translate request, and Stack Overflow is not a free code translation service. Giving "points" or "starting points" on the other hand is very broad. Thus, please make an attempt yourself to translate this to Julia, and once you get stuck, please [edit] the question to contain your (non-working) Julia code and ask a specific question about that. – Adriaan Jul 02 '20 at 17:09
  • 5
    This quite clearly isn't a translate request — please do not close it as such. It's a concrete question about the capabilities of an API that has already garnered a productive answer. – mbauman Jul 02 '20 at 22:19

1 Answers1

8

What led you to believe that Interpolations.jl works only for two-dimensional data?

julia> a = rand(1:100, 10, 10, 10);

julia> using Interpolations

julia> itp = interpolate(a, BSpline(Linear()));

julia> v = itp(1.4, 2.3, 3.7)
55.24
Nils Gudat
  • 13,222
  • 3
  • 39
  • 60
  • I see. Maybe I was not clear... I don't want to interpolate in order to calculate the value of my function in a specific point out of my mesh. I want to to interpolate the whole set of data into a whole new different mesh. Say I have a function of x, y and t gridded over a 100x100x100 mesh. I need to rediscribe this function over a 25X25X25 mesh. Was that clear? I'm sorry! That's because the method for solving forward problems I use produce far better solution over a refined mesh. But for other calculations (a inverse problem) it just slow down my code. Thanks anyway! – Gabriel Neves Jul 02 '20 at 22:03
  • 2
    Just pass vectors to `itp()` call to evaluate it on many locations: `itp(1.5:9.5, 1.2:9.2, 2:2:10)` or some such. – mbauman Jul 02 '20 at 22:17
  • 1
    That's it! Thank you so much! I was being misled by my matlab background, but it was quite simple! Getting more and more familiar with julia! – Gabriel Neves Jul 02 '20 at 23:11