How to extract the the right X,Y,Z value for obtaining the best contour plot similar than the complete contour

1 次查看(过去 30 天)
If I have a matrix A that contains 1041 rows with 3 columns (X, Y, Z)
How to extract exaclty 424 row-values from A that fits the best contour plot similar than the contour with all the rows values?
find attached A matrix [1041,4]. I would like to obtain the B matrix [424,4] still represent the best way the contour plot of:
x = A(:,1);
y = A(:,2);
z = A(:,3);

采纳的回答

KSSV
KSSV 2020-5-29
编辑:KSSV 2020-5-29
Option 1:
load("A.mat") ;
x = A(:,1);
y = A(:,2);
z = A(:,3);
m = 21 ; n = 21 ; % can be changed
xi = linspace(min(x),max(x),m) ;
yi = linspace(min(y),max(y),n) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
idx = ~isnan(Z) ;
iwant = [X(idx) Y(idx) Z(idx)] ;
Option 2:
load("A.mat") ;
x = A(:,1);
y = A(:,2);
z = A(:,3);
[c,ia,ib] = unique(y) ;
N = length(c) ;
iwant = cell(N,1) ;
for i = 1:N
xi = x(ib==i) ;
yi = y(ib==i) ;
zi = z(ib==i) ;
%
n = round(length(xi)/2) ; % This you can chnage if you want
xxi = linspace(min(xi),max(xi),n)' ;
yyi = c(i)*ones(n,1) ;
zzi = interp1(xi,zi,xxi) ;
iwant{i} = [xxi yyi zzi] ;
end
iwant = cell2mat(iwant) ;
subplot(121)
scatter(x,y,50,z,'filled')
colorbar
title("Original")
subplot(122)
scatter(iwant(:,1),iwant(:,2),50,iwant(:,3),'filled')
colorbar
title("downsampled to best") ;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by