How to compare two measurement datas from 2 different devices?
37 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
Star Strider
el 26 de Sept. de 2025 a las 13:27
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.
.
4 comentarios
Star Strider
hace alrededor de 15 horas
Editada: Star Strider
hace alrededor de 1 hora
Yes.
First, create the individual vectors for the concatenated 'X', 'Y', and 'Z' data, save them to a matrix or table (I chose a table here), then save the table to a .csv file.
Example --
tic
files = dir('*.csv');
NrFiles = numel(files)
x1 = zeros(numel(files),1);
x2 = zeros(numel(files),1);
y1 = zeros(numel(files),1);
y2 = zeros(numel(files),1);
for k = 1:NrFiles
A = readmatrix(files(k).name);
[x1(k,:),x2(k,:)] = bounds(A(:,1));
[y1(k,:),y2(k,:)] = bounds(A(:,2));
FZ{k} = scatteredInterpolant(A(:,1), A(:,2), A(:,3), 'nearest', 'none');
vn{k} = extractBefore(files(k).name, '.');
fprintf('\nFile %d: %s', k, files(k).name)
end
fprintf('\n\n')
toc
xcyclen = 2.5E+2; % Vector Lengths Of 'xc' and 'yc'
xc = linspace(min(x1), max(x2), xcyclen); % Reduce Interpolation Matrix Size
yc = linspace(min(y1), max(y2), xcyclen); % Reduce Interpolation Matrix Size
[Xc,Yc] = ndgrid(xc, yc);
figure
hold on
for k = 1:NrFiles
Z{k} = FZ{k}(Xc, Yc);
hs = scatter3(Xc, Yc, Z{k}, '.', DisplayName=vn{k});
hsc{k,:} = hs(1);
end
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Interpolated ''scatter3'' Plots')
legend([hsc{:}], Location='best')
daspect([5 5 1])
view(-27,30)
grid on
toc
Zcat = cat(3,[Z{:}]);
Xcr = repmat(Xc, 1, numel(Z));
Ycr = repmat(Yc, 1, numel(Z));
% Sizes = [size(Xcr); size(Ycr); size(Zcat)]
figure
scatter3(Xcr(:), Ycr(:), Zcat(:), '.')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Combined (Concatenated) Interpolated ''scatter3'' Plots')
figure
surf(Xcr, Ycr, Zcat, EdgeColor='interp')
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Z')
title('''surf'' Plot of ''Z'' Data')
toc
Xcrv = Xcr(:); % Create Vectors For 'table'
Ycrv = Ycr(:); % Create Vectors For 'table'
Zcatv = Zcat(:); % Create Vectors For 'table'
Concatenated_Data = table(Xcrv, Ycrv, Zcatv, VariableNames={'X','Y','Z'})
writetable(Concatenated_Data, 'Concatenated_Data.csv')
Check = readtable('Concatenated_Data.csv')
figure
scatter3(Check{:,1}, Check{:,2}, Check{:,3}, 15, Check{:,3}, '.')
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Z')
title('''scatter3'' Plot of ''X'', ''Y'', ''Z'' Data From ''.csv'' File')
toc
Ths 'xcyclen' vslue (that determines the lengths of those vectors and therefore the size of the interpolation matrix) can be whatever you want. I chose a smaller value here to conserve memory and shorten processing time. This value is about 1% of the matrix sizes.
EDIT -- (30 Sep 2025 at 13:54)
There are several overlapping points, so calculaitng the mean of them (and the 95% confidence interval) simply requires one accumarray call for each metric (mean and standard error of the mean).
Example --
[G,Xs,Ys] = findgroups(Xcrv, Ycrv);
Zmean = accumarray(G,Zcatv, [], @(x)mean(x,'omitnan')); % Regional 'mean'
Zmeanm = reshape(Zmean, numel(xc), numel(yc)); % Reshape Vector To Matrix
t95 = tinv([0.025 0.975],NrFiles-1)
Zsem = accumarray(G, Zcatv, [], @(x)std(x,'omitnan')/sqrt(NrFiles)); % Regional SEM
Zsemm = reshape(Zsem, numel(xc), numel(yc)); % Reshape Vector To Matrix
Zci95{1} = Zmean + t95(1) * Zsem; % Lower 95% CI Bound Matrix
Zci95{2} = Zmean + t95(2) * Zsem; % Upper 95% CI Bound Matrix
[Zmax,idx] = max(Zmean(:));
Ex_CI95 = [Zci95{1}(idx); Zmax; Zci95{2}(idx)]
figure
surf(Xc, Yc, Zmeanm, EdgeColor='interp')
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Z')
title('''surf'' Plot Of Mean ''Z'' Data')
toc
I did not plot the 95% confidence interval surfaces, since they are likely would not be visible. They are also extremely close to the mean surface, each separated from it by 0.0003.
EDIT -- (30 Sep 2025 at 15:54)
Saving the averages to a file is similarly straightforward, although recovering the matrices requires reshape calls --
Concatenated_Mean = table(Xc(:), Yc(:), Zmean(:), [Zci95{1}], [Zci95{2}], VariableNames={'Xc','Yc','Zmean','CI025','CI975'})
Xv = Concatenated_Mean{:,1};
Yv = Concatenated_Mean{:,2};
Zv = Concatenated_Mean{:,3};
Xvu = unique(Xv);
Xdim = numel(Xvu)
Xmtx = reshape(Xv,Xdim,[]);
Ymtx = reshape(Yv,Xdim,[]);
Zmtx = reshape(Zv,Xdim,[]);
figure
surf(Xmtx, Ymtx, Zmtx, EdgeColor='interp')
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Z')
title('''surf'' Plot Of Mean ''Z'' Data Read From Table')
toc
Writing it to a .csv file and reading it would work similarly to the previous example.
EDIT -- (01 Oct 2025 at 00:26)
Improved code created in previous EDIT.
.
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!