error from Interpolation of the attached data
Afficher commentaires plus anciens
could you please help me debug Matlab code for interpolation of the attached data?
Thanks,
load('data.mat');
figure(1);plot(x1,y1);
figure(2);plot(x2,y2);
assert(numel(unique(x1))==numel(x1),'Replicated point(s) in x1')
%assert(numel(unique(x2))==numel(x2),'Replicated point(s) in x2')
As the error message you got says, there is a duplicated value in the x2 vector -- not allowed in interp1
ix=find(diff(x2)==0) % find who are the culprits
format longe
x2(ix:ix+1)
[x2,ia]=unique(x2);
y2=y2(ia);
x= linspace(700,1400,701).';
y11 = interp1(x1,y1,x);
y22 = interp1(x2,y2,x);
figure(3);plot(x,y11);
figure(4);plot(x,y22);
Réponse acceptée
Plus de réponses (1)
Jan
le 28 Mai 2026 à 3:20
Then:
load('data.mat');
figure;
plot(uniquify(x1), y1)
Catégories
En savoir plus sur Write Unit Tests dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







