# I'm having a problem averaging multiple curves using interp1

7 次查看（过去 30 天）
Philip Krämer 2023-3-11

Hi everyone.
I have multiple polarisation curves that I want to display the averge of. I tried using linspace to create a base vector and interpolating using interp1. Unfortunately that hasn't properly worked for me and I was hoping someone might be able to help.

### 采纳的回答

Chris 2023-3-11

1. You take the mean and max of the U values; I believe you want the I values instead.
2. You have plenty of data points, so the default linear interpolation will follow the trend better.
3. Some data at the end will have to be excluded from the mean curve. You could use the 'omitnan' flag, but that will cause a discontinuity in the curve.
% Mittelung mehrerer Messungen
clearvars
[filenames, pathname] = uigetfile('MultiSelect', 'on', '*.*');
fullname = fullfile(pathname,filenames);
clear savename
for z = 1:length(fullname)
end
IVC_mean = cell (3,length(fullname));
var = zeros(1,length(fullname));
Names = string(var);
Imax = zeros (1,length(fullname));
Umax = zeros (1,length(fullname));
Umin = zeros (1,length(fullname));
for z = 1:length(fullname)
% Messdaten
Ewe = Daten{1,z}(:,7);
I = Daten{1,z}(:,8).*1000;
Ismooth = smoothdata(I,'sgolay');
% Details der Messung
savename{1,z} = extractBefore(filenames{1,z},".");
Names(z) = savename {1,z};
% sortieren
IVC_mean{1,z} = Ewe;
IVC_mean{2,z} = abs(Ismooth);
IVC_mean{3,z} = extractAfter(strrep(savename{1,z},'_',' '),' ');
% % outlier
% pp = isoutlier(IVC_mean{2,z});
% ind = find(pp);
% IVC_mean{4,z} = ind;
% IVC_mean{5,z} = IVC_mean{2,z};
% IVC_mean{5,z}(ind) = NaN;
% einzeln plot
h = scatter(IVC_mean{2,z},IVC_mean{1,z});
xlabel(['I']);ylabel(['U']);
hold on
% Grenzen für xq
% IVC_mean{6,z} = min(IVC_mean{1,z});
% IVC_mean{7,z} = max(IVC_mean{1,z});
IVC_mean{6,z} = min(IVC_mean{2,z});
IVC_mean{7,z} = max(IVC_mean{2,z});
Umin(z) = IVC_mean{6,z};
Umax(z) = IVC_mean{7,z};
end
%
% Interpolation
Umin = min(Umin);
Umax = max(Umax);
% vorgegebener Bezugsvektor
UC = linspace(Umin,Umax,10000);
for z = 1:length(fullname)
% IVC_mean{8,z} = interp1(IVC_mean{2,z},IVC_mean{1,z},UC,'spline');
IVC_mean{8,z} = interp1(IVC_mean{2,z},IVC_mean{1,z},UC,'linear');
h2 = plot(UC,IVC_mean{8,z},'k--','LineWidth',2);
hold on
end
mfit = mean(cat(1,IVC_mean{8,:}));
plot(UC, mfit,'m','LineWidth',2);
##### 5 个评论显示 3更早的评论隐藏 3更早的评论
Philip Krämer 2023-3-12
Chris 2023-3-12
Bitte sehr!

### 更多回答（1 个）

Walter Roberson 2023-3-11
h = scatter(IVC_mean{2,z},IVC_mean{1,z});
So {1} is used as y values and {2} is used as x values.
IVC_mean{6,z} = min(IVC_mean{1,z});
IVC_mean{7,z} = max(IVC_mean{1,z});
min and max of the y values.
Umin = min(Umin);
Umax = max(Umax);
UC = linspace(Umin,Umax,10000);
smallest y and greatest y
IVC_mean{8,z} = interp1(IVC_mean{2,z},IVC_mean{1,z},UC,'spline');
you pass in known x values and corresponding known y values and you query based on UC, which is based on y values, not on x values.

### 类别

Help CenterFile Exchange 中查找有关 Smoothing 的更多信息

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by