MATLAB Answers

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

조회 수: 4(최근 30일)
Philippe Corner
Philippe Corner 29 May 2020
편집: KSSV 29 May 2020
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);

  댓글 수: 0

Sign in to comment.

채택된 답변

KSSV
KSSV 29 May 2020
편집: KSSV 29 May 2020
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

Sign in to comment.

추가 답변(0개)


Translated by