error from Interpolation of the attached data
Show older comments
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);
Accepted Answer
More Answers (1)
Jan
on 28 May 2026
Then:
load('data.mat');
figure;
plot(uniquify(x1), y1)
Categories
Find more on Write Unit Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






