INTRO: I created a table T using the following command lines:
xvector = 1:1:10; yvector = 1:3:20; numX = numel(xvector); numY = numel(yvector); yvector = repmat(yvector(:),numX,1); xvector = repmat(xvector ,numY,1); COORDINATES= [xvector(:) yvector]; VALUE=(1:1:numX*numY)'; T=[COORDINATES VALUE];
The first two columns are the x and y coordinates and the third is the corresponding value for each x,y-pair.
GOAL: I want to construct a new table TNEW selecting specific elements of T.
So I introduce the parameter SKIP=value (=to skip elements of T). SKIP=1 means all elements of T are used, thus TNEW=T. SKIP=2 means: use every second ELEMENT of T in X AND in Y directions. SKIP=3 means: use every third ELEMENT, and so on.
REMARK: there is a difference between using every n-ten ELEMENT IN X AND Y DIRECTION and not using every n-ten raw along the table: First, x is constant and y runs in arbitrary steps. Thus, for SKIP=4, every fourth raw will be selected until a serie of y is finished (before it starts repeating for a new value of x). Second, the new value of x are also selected in steps of four, thus all values of y for the non-fourth x are also excluded.
To obtain this goal, I wrote the following lines:
SKIP=2;ix=mod(T(:,1),SKIP)~=0 & mod(T(:,2),SKIP)~=0;TNEW = T(ix,:);
It works correct for SKIP=1 or SKIP=2, as you can see if you run all the command lines above. PROBLEM: it does not work for SKIP>2 and I don't know how to improve or may be to change it.
I wonder if someone has an idea to achie the same goal for arbitrary n.
Thank you in advance for your attention
Emerson
Best Answer