Simple Example

This is a simple example of using regularizeNd.
clc; clear; close all;
This example uses the etopo_loihi sample data packaged with regularizeNd. Data extracted from:
NOAA National Centers for Environmental Information: DEM Global Mosaic (contains ETOPO 2022 and higher-resolution multibeam sources), centred on Kamaʻehuakanaloa Seamount (18.92°N, 155.27°W). DOI: https://doi.org/10.25921/fd45-gt74. Accessed March 29, 2026.
Note this data set is undersampled and course to keep from attaching a large .mat file. The full structure of the top of the volcano is not resolved. This is due to not enough data and not regularizeNd.
SEAMOUNT_COORDINATES = [-155.27 18.92];
 
data = load('a01_etopo_loihi.mat');
x = double(data.x);
y = double(data.y);
z = double(data.z);
 
 
xLimits = [min(x), max(x)];
yLimits = [min(y), max(y)];
 
xGrid = {linspace(xLimits(1) - eps(xLimits(1)), xLimits(2) + eps(xLimits(2)), 480), ...
linspace(yLimits(1) - eps(yLimits(1)), yLimits(2) + eps(yLimits(2)), 481)};
 
smoothness = 0.000001;
zGrid = regularizeNd([x,y], z, xGrid, smoothness, 'cubic');
% equivalents ways to call regularizeNd
% zGrid = regularizeNd([x,y], z, xGrid, smoothness, 'cubic', 'normal');
 
% Upsample grid since we are using cubic interpolation
zFunction = griddedInterpolant(xGrid, zGrid);
xGrid2= {linspace(xLimits(1) - eps(xLimits(1)), xLimits(2) + eps(xLimits(2)), 2000), ...
linspace(yLimits(1) - eps(yLimits(1)), yLimits(2) + eps(yLimits(2)), 2001)};
xGrid2Expanded = cell(2,1);
[xGrid2Expanded{:}] = ndgrid(xGrid2{:});
zGrid2 = zFunction(xGrid2Expanded{1}, xGrid2Expanded{2});
 
figure;
surfaceHandle = surf(xGrid2{:}, zGrid2',"EdgeColor","none","FaceColor","interp");
hold on;
contour3(xGrid2{:}, zGrid2', 22, 'k', 'LineWidth', 0.45);
GRAY = [0.5 0.5 0.5];
scatter3(x, y, z, 10, GRAY, 'filled');
colormap(turbo(256));
clim([-5400 -900]);
view(329.7, 61);
xlabel('Longitude');
ylabel('Latitude');
zlabel('Depth (m)');
grid on;
axis tight;
title('3D bathymetry view');
ylabel(colorbar, "Depth (m)");
% datatip(surfaceHandle, SEAMOUNT_COORDINATES(1), SEAMOUNT_COORDINATES(2), zFunction(SEAMOUNT_COORDINATES(1), SEAMOUNT_COORDINATES(2)));
 
% Copyright (c) 2016-2026 Jason Nicholson
% Licensed under the MIT License
% See LICENSE file in project root