Boundary and smooth the figure

6 vues (au cours des 30 derniers jours)
Abdulkarim Almukdad
Abdulkarim Almukdad le 1 Mar 2021
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 commentaires
Mathieu NOE
Mathieu NOE le 4 Mar 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')
Abdulkarim Almukdad
Abdulkarim Almukdad le 4 Mar 2021
Thank you very much for your help. I think I have an idea that might solve this issue but I have zero knowledge about how to do it on matlab unfortunately. I think if the data of each side of the x is ploted and found its boundary, then the combination of both boundaries can do the job. I will try to separate the sides from excel manually by checking each column from simple plottings then I will check what will happen in matlab.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by