tl; dr: Change xsim and ( ssim ) from scalars to vectors of the same size as ksim and zsim
Output = interpn (ks, xs, zs, ss, ... kprime, ... ksim, ... repmat(xsim, size(ksim)), ... % <-- here zsim, ... repmat(1, size(ksim)), ... % <-- and here 'linear');
Explanation:The inputs ksim , xsim , zsim and ssim must all have the same shape, so that at each common position in this form, each input acts as a "interpolated index" component for the interpolated object. Please note that although they should all have the same shape, this shape can be arbitrary in terms of size and dimensions.
Conversely, if you pass vectors of different sizes (after all, a scalar is a vector of length 1), they are instead interpreted as components of the ndgrid construct. So you actually said interpn to evaluate all interpolations over the grid defined by the ksim and zsim (and your xsim and ssim ). That's why you got the output with a 2D grid.
Note that the same pattern applies to construction vectors (i.e., Ks, xs, zs, and ss), that is, you could use the “vector syntax” instead of the “general shape” syntax to define the mesh, i.e.
Output = interpn(kgrid, x, z, s, kprime, % ...etc etc
and you would get the same result.