MATLAB: Is interpolation between matrices of different sizes possible

interpolation

I would like to find an interpolated curve between two curves/matrices. First is 2×2290 and the second 2×2316. How could I do it?

Best Answer

Perhaps the code below will do what you want.
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 18;
markerSize = 20;
% Read in curve 1.
s1 = importdata('sscurve1.txt')
x1 = s1.data(:, 1)
y1 = s1.data(:, 2)
% Plot curve 1
plot(x1, y1, 'b-', 'LineWidth', 2);
grid on;
hold on;
% Read in curve 2.
s2 = importdata('sscurve2.txt')
x2 = s2.data(:, 1)
y2 = s2.data(:, 2)
% Plot curve 2
plot(x2, y2, 'r-', 'LineWidth', 2);
% Curve 2 has more points than curve 1 so let's interpolate curve 1
% to have as many points as curve 2
x = 1 : length(x2);
x1Interp = interp1(1:length(x1), x1, x);
y1Interp = interp1(1:length(y1), y1, x);
% Get rid of nans
nanIndexes = isnan(x1Interp) | isnan(y1Interp);
x1Interp(nanIndexes) = [];
y1Interp(nanIndexes) = [];
x2(nanIndexes) = [];
y2(nanIndexes) = [];
% Plot this new curve.
% plot(x1Interp, y1Interp, 'g-', 'LineWidth', 2);
% Average this new curve in with curve 2. Need to transpose first with '
xAve = (x1Interp' + x2)/2;
yAve = (y1Interp' + y2)/2;
% Plot this new curve in black.
plot(xAve, yAve, 'k-', 'LineWidth', 2);
legend('Curve 1', 'Curve 2', 'Average Curve', 'Location', 'south');
Related Question