-
Notifications
You must be signed in to change notification settings - Fork 0
/
resample_data_function.m
27 lines (21 loc) · 1.03 KB
/
resample_data_function.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
%% This function resamples a X by X data into a Y by Y data
% it takes structs as an input
function resampledStruct = resample_data_function(inputStruct, newSize)
% Initialize the result struct
resampledStruct = struct();
% Loop through all fields in the input struct
fieldNames = fieldnames(inputStruct);
for i = 1:numel(fieldNames)
fieldName = fieldNames{i};
originalData = inputStruct.(fieldName);
% Create X and Y coordinates for the new grid
[xq, yq] = meshgrid(linspace(1, size(originalData, 1), newSize), ...
linspace(1, size(originalData, 2), newSize));
% Create X and Y coordinates for the original data
[xx, yy] = meshgrid(1:size(originalData, 1), 1:size(originalData, 2));
% Perform bilinear interpolation to resample the data
resampledData = interp2(xx, yy, originalData, xq, yq, 'nearest');
% Assign the resampled data to the result struct
resampledStruct.(fieldName) = resampledData;
end
end