I'm having a problem averaging multiple curves using interp1

조회 수: 7 (최근 30일)
Philip Krämer
Philip Krämer 2023년 3월 11일
댓글: Chris 2023년 3월 12일
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.
Thank you in advance!

채택된 답변

Chris
Chris 2023년 3월 11일
편집: 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)
load (fullname{1,z})
loadDaten{1,z} = Daten;
end
Daten = loadDaten;
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
Philip Krämer
Philip Krämer 2023년 3월 12일
Thanks for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
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