I am attempting to set up some code to extract certain elements of a matrix, and keeping only these values in another matrix, in the order they were extracted.
Example: If I have a random 1X20 matrix, but want only every Nth = 5th element beginning with 4 and 5, I would want it to construct a new matrix (1x8) consisting only of 4, 5, 9, 10, 14, 15, 19, 20.
What I have so far is:
r = rand(1,20);
n = 5;
a = r(4 : n : end);
b = r(5 : n : end);
So instead of two separate matrices, I instead want one matrix in its original chronological order (again, a 1x8 matrix consisting of the elements in the order of 4,5,9,10,14,15,19,20). Essentially, I'd like to be able to do this for any number of values while still maintaining the original order the elements were in.