Boundary and smooth the figure
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
I have a very larg data (X, Y, Z)  and I used some codes to read the data then remove the columns that contain NaN. The below codes are used after the previous description to plot a 2D graph or 3D with Z being indicated by colors. I tried pcolor and surf but I'm getting the same two problems; 1- the figure is supposed to be perfect x-shape with an angle of 30, but in the middle some portions are connected together which is incorrect. 2- I'm looking for a way to smooth the figure in which the portions where high value of Z be distributed somehow on the adjacent points so that it can be very clear that at this location we have high value of Z (i.e., in my plots this high Z value is showing as a point). I hope that someone can help me doing this. Thanks in advance
x0 = min(x) ; x1 = max(x) ; 
y0 = min(y) ; y1 = max(y) ; 
xi = linspace(x0,x1,150) ; 
yi = linspace(y0,y1,150) ; 
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
% Get boundary coordinates 
idx = boundary(x,y) ; 
xb = x(idx) ; yb = y(idx) ; 
% Get points lying inside the boundary 
idx = inpolygon(X,Y,xb,yb) ;
Z(~idx) = NaN ;
f=pcolor(X,Y,Z);
colorbar
shading interp 
axis('equal')

8 Kommentare
  Mathieu NOE
      
 am 4 Mär. 2021
				I was not 100 % successful this time 
I increased the "shrink" factor (in the  boundary function) so that the triangular areas are reduced but they did not completely vanished
I tried a couple of other approaches but without much benefit
I believe I have to find a robust way to introduce a couple of more points to create the missing corner of the boundary

clc
close all
clear all
num = readtable("01)30.xlsx") ; 
% Take all the data under each variable name
x=num{1:1:end, contains(num.Properties.VariableNames, 'x')};
y=num{1:1:end, contains(num.Properties.VariableNames, 'y')};
z=num{1:1:end, contains(num.Properties.VariableNames, 'v')};
% Convert the matrix to 1 column only (scalar)
x=x(:);
y=y(:);
z=z(:);
% Delete rows that contain NaNs with reference to the variable z
i=1; [m,n]=size(x); 
    while i<=m
        if isnan(z(i,1))
        x(i,:)=[];
        y(i,:)=[];
        z(i,:)=[];
        i=i-1;      
        end
        i=i+1; [m,n]=size(x);  
    end
x0 = min(x) ; x1 = max(x) ; 
y0 = min(y) ; y1 = max(y) ; 
xi = linspace(x0,x1,150) ; 
yi = linspace(y0,y1,150) ; 
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
% Get boundary coordinates 
idx = boundary(x,y,1) ; 
xb = x(idx) ; yb = y(idx) ; 
a = 0.5;
nd = [a a]/2;
dd = [1 -1+a];
xxb = filtfilt(nd,dd,xb);
yyb = filtfilt(nd,dd,yb);
figure(1),
plot(xb,yb,'*-b',xxb,yyb,'r');
% Get points lying inside the boundary 
% idx = inpolygon(X,Y,xb,yb) ;
idx = inpolygon(X,Y,xxb,yyb) ;
Z(~idx) = NaN ;
figure(2),
f=pcolor(X,Y,Z);
colorbar
shading interp 
axis('equal')
Antworten (0)
Siehe auch
Kategorien
				Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


