Problem 378. Inhomogenous Depth Scale Interpolation
I recently came across a dataset for physical ocean parameters such as temperature and salinity that provided data in the form of a 3-Dimensional array of depths and a 3-Dimensional array of the parameters where each point on the first two dimensions corresponds to a latitude and longitude, respectively, and the points in the third dimension corresponds to depths.
Given a target depth, return the linearly interpolated values of the data at that depth without using the keywords for or while in your code.
For example, if Z and V are arrays with size [ M, N, D ], the output matrix V2 would be of size [ M N ].
Test Case Details:
- The depth array, Z, will always start at 0 and end at 1, which are also the bounds of the target depth d. This is so that you do not have to handle "edge" cases.
- The depth array, Z, will always be sorted in the third dimension.
- Both input arrays will be the same size.
- The test cases are randomly generated and your solution is tested against a simple for-looping code.
Solution Stats
Problem Comments
-
2 Comments
Rafael S.T. Vieira
on 10 Nov 2020
Please, bmtran, don't use isequal with floats, prefer to use abs(a-b) < tol. Unless I use the function interp1 exactly like you did, my solution cannot pass the test suite. Please try my commented code (and the difference between the solutions is at the order of 1e-15).
goc3
on 19 Feb 2023
The test suite has been updated to not use isequal().
Solution Comments
Show commentsProblem Recent Solvers7
Suggested Problems
-
Least common multiple of many numbers
235 Solvers
-
293 Solvers
-
122 Solvers
-
Project Euler: Problem 2, Sum of even Fibonacci
2299 Solvers
-
Getting the absolute index from a matrix
246 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!