1

I have a matrix of XYZ data, X and Y are in a regular "meshgrid format", I need to reduce the number of points by some factor. sample:

stepXY = 1;
X = 1:stepXY:100;
Y = 1:stepXY:80;

[Xm,Ym] = meshgrid(X,Y);

XYZ = [Xm(:) Ym(:)]';
XYZ(3,:) = 7;

How to get a XYZ2 = XYZ as a step of 10 (in XY) instead of 1? I can't just get an element after each 10 steps becouse this you result in something like:

1 1  7
1 10 7
.
.
.
2 1 7 <==== look, X should be 10 here.
Pedro77
  • 5,176
  • 7
  • 61
  • 91

2 Answers2

1

You can create new vectors of X and Y values with your new step size, then use ismember to find indices where your old values are members of your new sets. For example, if you want your new step size in both the x and y directions to be 10, you would do this:

newStep = 10;
newX = 1:newStep:100;
newY = 1:newStep:80;
index = ismember(XYZ(1, :), newX) & ismember(XYZ(2, :), newY);
XYZ2 = XYZ(:, index);

XYZ2 =

  Columns 1 through 24

     1     1     1     1     1     1     1     1    11    11    11    11    11    ...
     1    11    21    31    41    51    61    71     1    11    21    31    41    ...
     7     7     7     7     7     7     7     7     7     7     7     7     7    ...
gnovice
  • 125,304
  • 15
  • 256
  • 359
0

Is this what you want:

Zm = X*0+7;  %or whatever your data is
XYZ = cat(3,Xm,Ym,Zm);
XYZ_subsample = XYZ(1:10:end,1:10:end,:);
Jed
  • 193
  • 11