fill missing point in data (x y z 3 columns data)
Afficher commentaires plus anciens
hello.
I have a data with three columns that have empty spaces inside.
For example, a data has 2500 rows (point) and its length and width are 50 x 60 = 3000
I want to grid this data and put (nan) in place of the blanks
The following plot is drawn with the plot(x,y,'.')
1 commentaire
Rena Berman
le 20 Sep 2021
(Answers Dev) Restored edit
Réponses (2)
You can use meshgrid to make x and y grids, and then ismember with the rows flag to find which pairs of x and y are missing:
% Some fake data that simulares your problem
[x,y]=meshgrid(1:10,1:10);
data=[x(:) y(:) rand(numel(x),1)];
% Remove 10 random indices
data(randperm(numel(x),10),:)=[];
scatter(data(:,1),data(:,2),'filled')
axis padded
% Make a grid using meshgrid, you'll need at least one point for each grid
% location in either x or y. Otherwise, specify the grid x and y
% explicitly for the first two arguments of meshgrid.
[xi,yi]=meshgrid(unique(data(:,1)), unique(data(:,2)));
notfound = ~ismember([xi(:) yi(:)],data(:,1:2),'rows');
data=[data; xi(notfound) yi(notfound) nan(sum(notfound),1)];
hold on
scatter(data(:,1),data(:,2),75)
legend('Pre','Post','Location','EastOutside')
% Generate some data
[x, y] = meshgrid(1:60, 1:50);
x = x(:);
y = y(:);
z = 1./((x-30).^2+(y-20).^2);
% make a square hole
[ix, iy] = meshgrid(20:30, 30:45);
ix = ix(:); iy=iy(:);
idx = sub2ind([50, 60], iy, ix);
x(idx)=[]; y(idx)=[]; z(idx)=[];
% Replace x,y,z with your data
plot(x, y, '*');
% get the grid from data x and y
xg = sort(unique(x));
yg = sort(unique(y));
[xg, yg] = meshgrid(xg, yg);
idx = ~ismember([xg(:) yg(:)], [x y], 'rows');
%idx(:)
xg(idx) = nan;
yg(idx) = nan;
figure
imagesc(isnan(xg) & isnan(yg))
axis xy
% Assign z
zg = nan(size(xg));
zg(~idx) = z;
figure
%imagesc(zg);
%axis xy
surfl(zg)
figure
imagesc(isnan(zg))
axis xy
whos
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



