Clear Filters
Clear Filters

How do i show the "delta" difference between the two plotted curves?

7 views (last 30 days)
I want to analyze the difference between the two plotted curves(fig 1) from two different codes. The zoomed-in version (fig 2). Is there any way i can get the "delta" difference in a much better and clearer manner since the coordinates are very close to each other? Maybe an interp function ? My code and .mat files are provided below. Any help is appreciated!
load coords_mine.mat
load coords_sir.mat
plot(a,b ,'.g') % code 1
hold on
axis equal
plot(x2,y2,'.b') % code 2
axis equal
delta = abs((b - y2)./y2) * 100;
xCenter = 1:1:length(b);
yCenter = (b+y2)/2;
for k = 1 : length(xCenter)
textLabel = sprintf('%.1f', delta(k));
text(xCenter(k), yCenter(k), textLabel, 'HorizontalAlignment', 'center')
end

Accepted Answer

Mathieu NOE
Mathieu NOE on 9 Sep 2024
Edited: Mathieu NOE on 9 Sep 2024
hello
you need to "realign" your two data sets vs common x vector - in other words we need to creat a new x vector and interpolate both y datas vs this new x vector - here I opted for pchip interpolation method.
the bottom plot is your delta vector , I picked only a few values to be displayed on the top plot
hope it helps !!
load coords_mine.mat
load coords_sir.mat
% take unique only x data
[a,ia,ic] = unique(a);
b = b(ia);
[x2,ia,ic] = unique(x2);
y2 = y2(ia);
% plot
figure(1);
subplot(211),
plot(a,b ,'.g') % code 1
hold on
plot(x2,y2,'.b') % code 2
% create common x axis data
xmin = max(a(1),x2(1));
xmax = min(a(end),x2(end));
xnew = linspace(xmin,xmax,300)';
% and interpolate y data using pchip method
bnew = interp1(a,b,xnew,'pchip');
y2new = interp1(x2,y2,xnew,'pchip');
delta = abs((bnew - y2new)./y2new) * 100;
xCenter = 1:30:length(bnew); % NB decimation factor 30 vs 300 original data points => 10 values displayed
yCenter = (bnew+y2new)/2;
yCenter = yCenter(xCenter);
for k = 1 : numel(xCenter)
textLabel = sprintf('%.3f', delta(xCenter(k)));
text(xnew(xCenter(k)), yCenter(k)*1.1, textLabel, 'HorizontalAlignment', 'center')
end
plot(xnew(xCenter),yCenter,'xk','markersize',15)
subplot(212),
plot(xnew,delta,'b') %

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!