How to compare two measurement datas from 2 different devices?

22 views (last 30 days)
Hallo,
I have two different csv measurements(xyz) from 2 different devices. One is a device doing spiral scanning and other is an interferometer. Since both of the devices will give different xyz. I am scanning the same workpiece in both devices. In order to do better comparison, i believe i need xyz almost close to each other for the devices,so how can i do it? Is the interpolation over common grid (x,y) works or is there any other better options?

Answers (1)

Star Strider
Star Strider about 3 hours ago
It would help to have the data, or at least a representative sample of it.
Without knowing more, I would create a grid over the dimensions of the (x,y) plane that included all those data, so the minimum of both the x-coordinates to the maximum of the both x-coordinates, and the same of the y-coordinates. You can create those grids using the ndgrid funciton. Then create surfaces of the data using the scatteredInterpolant function, and then use the ndgrid results to plot them.
That might go something like this --
x1 = linspace(1, 2, 10);
y1 = linspace(2, 3, 11);
z1 = randn(numel(x1), numel(y1));
x2 = linspace(2, 4, 12);
y2 = linspace(1, 5, 10);
z2 = randn(numel(x2), numel(y2));
[X1,Y1] = ndgrid(x1, y1);
figure
stem3(X1, Y1, z1, 'filled')
grid on
xlabel('X_1')
ylabel('Y_1')
zlabel('Z_1')
title('Data Set #1')
[X2,Y2] = ndgrid(x2, y2);
figure
stem3(X2, Y2, z2, 'filled')
grid on
xlabel('X_2')
ylabel('Y_2')
zlabel('Z_2')
title('Data Set #2')
FZ1 = scatteredInterpolant(X1(:), Y1(:), z1(:), 'nearest', 'none');
FZ2 = scatteredInterpolant(X2(:), Y2(:), z2(:), 'nearest', 'none');
x3 = linspace(min(min(x1),min(x2)), max(max(x1),max(x2)), 20);
y3 = linspace(min(min(y1),min(y2)), max(max(y1),max(y2)), 20);;
[X3,Y3] = ndgrid(x3, y3);
Z1i = FZ1(X3, Y3);
Z2i = FZ2(X3, Y3);
figure
stem3(X3, Y3, Z1i, 'filled', DisplayName='Z1i')
hold on
stem3(X3, Y3, Z2i, 'filled', DisplayName='Z2i')
hold off
grid on
legend(Location='best')
xlabel('X_3')
ylabel('Y_3')
zlabel('Z_3')
title('Data Sets Combined')
Much depends on your data and the result you want.
.
  2 Comments
Jes
Jes on 26 Sep 2025 at 13:44
Edited: Jes on 26 Sep 2025 at 13:48
Is it ok, if i share 5 csv files?. but it is from same device. I did this thing to check the repeatability. Since these csv files have different xyz values.
Star Strider
Star Strider on 26 Sep 2025 at 14:44
Edited: Star Strider 10 minutes ago
Sure!
This takes a while to run.
t appears to work --
tic
files = dir('*.csv')
files = 5×1 struct array with fields:
name folder date bytes isdir datenum
x1 = zeros(numel(files),1);
x2 = zeros(numel(files),1);
y1 = zeros(numel(files),1);
y1 = zeros(numel(files),1);
for k = 1:numel(files)
A{k,:} = readmatrix(files(k).name);
[x1(k,:),x2(k,:)] = bounds(A{k}(:,1));
[y1(k,:),y2(k,:)] = bounds(A{k}(:,2));
SzA = size(A{k})
FZ{k} = scatteredInterpolant(A{k}(:,1), A{k}(:,2), A{k}(:,3), 'nearest', 'none');
vn{k} = extractBefore(files(k).name, '.');
figure
% stem3(A{k}(:,1), A{k}(:,2), A{k}(:,3), '.')
scatter3(A{k}(:,1), A{k}(:,2), A{k}(:,3), '.')
xlabel('X')
ylabel('Y')
zlabel('Z')
title(files(k).name)
end
SzA = 1×2
23691 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzA = 1×2
23693 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzA = 1×2
23690 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzA = 1×2
23690 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzA = 1×2
23690 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% [x1 x2]
% [y1 y2]
toc
Elapsed time is 4.123727 seconds.
xc = linspace(min(x1), max(x2), 2.5E+2); % Reduce Interpolation Matrix Size
yc = linspace(min(y1), max(y2), 2.5E+2); % Reduce Interpolation Matrix Size
[Xc,Yc] = ndgrid(xc, yc);
figure
hold on
for k = 1:numel(A)
Z{k} = FZ{k}(Xc, Yc);
% stem3(Xc, Yc, Z{k}, '.', DisplayName=vn{k})
% stem3(Xc, Yc, Z{k}, '.', DisplayName=vn{k}, BaseValue=-4)
hs = scatter3(Xc, Yc, Z{k}, '.', DisplayName=vn{k});
hsc{k,:} = hs(1);
end
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
% title('Interpolated ''stem3'' Plots')
title('Interpolated ''scatter3'' Plots')
legend([hsc{:}], Location='best')
% axis('equal')
daspect([5 5 1])
view(-27,30)
grid on
toc
Elapsed time is 10.426519 seconds.
Zcat = cat(3,Z{:});
Zmean = mean(Zcat, 3, 'omitnan');
t95 = tinv([0.025 0.975],numel(Z)-1)
t95 = 1×2
-2.7764 2.7764
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Zsem = std(Zcat, [], 3, 'omitnan')/sqrt(numel(Z));
Zci025 = t95(1) * Zsem + Zmean;
Zci975 = t95(2) * Zsem + Zmean;
Summary_Stats = [mean(Zci025,'all','omitnan'); mean(Zmean,'all','omitnan'); mean(Zci975,'all','omitnan')]
Summary_Stats = 3×1
-1.4262 -1.4245 -1.4229
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
surf(Xc, Yc, Zmean, EdgeColor='interp')
% hold on
% surf(Xc, Yc, Zci025, EdgeColor='interp', FaceAlpha=0.5, EdgeAlpha=0.5)
% surf(Xc, Yc, Zci975, EdgeColor='interp', FaceAlpha=0.5, EdgeAlpha=0.5)
% hold off
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Z')
% title('Mean of ''Z'' Data & 95% Confidence Intervals')
title('Mean of ''Z'' Data')
toc
Elapsed time is 16.147413 seconds.
% figure
% surf(Xc, Yc, Zci025, EdgeColor='interp', FaceAlpha=0.75, EdgeAlpha=0.75)
% hold on
% surf(Xc, Yc, Zci975, EdgeColor='interp', FaceAlpha=0.25, EdgeAlpha=0.25)
% hold off
% colormap(turbo)
% colorbar
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
% title('Separate Confidence Intervals of ''Z'' Data')
%
%
% toc
% figure
% hold on
% for k = 1:numel(A)
% surf(Xc, Yc, Z{k}, DisplayName=vn{k}, EdgeColor='interp')
% end
% hold off
% colormap(turbo)
% colorbar
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
% title('Interpolated ''surf'' Plot')
% % legend(Location='best')
% % axis('equal')
% daspect([2,2,1])
% view(-27,30)
% grid on
toc
Elapsed time is 16.149665 seconds.
I reduced the sizes of the interpolation matrices to about 1% of their original sizes, in the interests of both memory usage and time. Change them as necessary.
Make appropriate changes to get the result you want.
EDIT -- (26 Sep 2025 at 17:03)
Added mean and coinfidence interval plots. However the confidence intervals are not easily visible (their differences from the mean are quite small), so I commented-out the plots of them.
EDIT -- (27 Sep 2025 at 15:24)
Converted stem3 plots to scatter3 plots to make them clearer,and because I could not get the 'BaseValue' name-value pair to work with the last stem3 plots. With the last one, it simply produced a completely black figure window.
.

Sign in to comment.

Categories

Find more on Line Plots 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!