Thank you for the responses. I have arrived at what I needed and hope it will help anyone in the future viewing this post.
First, each Ci is a different set so C can be a (mx*my+1)-by-N matrix of zeros where each row would a different set Ci.
C = zeros(mx*my+1,N);
Next, the logic of lines 5 and 7 can be coded as below where col_t and col_f are the indices of the column to change when the condition is true or false respectively. They are initialized to 1 before the for loop.
%%line 5
row = (i-1)*mx+j;
C(row,col_t) = n;
col_t = col_t + 1;
%%line 7
row = mx*my+1;
C(row,col_f) = n;
col_f = col_f + 1;
Finally, after line 11 and before the for loop of line 12, you can extract the subset with the following code:
Ci = C(i,:);
And the condition on line 13 would be as Titus answered:
if ismember(n,Ci)