When X is a row vector and Y is a row vector, and flag is a vector, then regardless of whether flag is a row vector or a column vector, the output of X(flag) will be a row vector and the output of Y(flag) would be a row vector. When you did [X(flag, Y(flag)] then that would be concatenating together two row vectors horizontally, and the result would be a row vector. Your plot attempt A(2,:) would then be trying to use row 2 of a row vector, which would not exist, and you would get an error
When X is a column vector and Y is a column vector, and flag is a vector, then regardless of whether flag is a row vector or a column vector, the output of X(flag) will be a column vector and the output of Y(flag) would be a column vector. When you did [X(flag, Y(flag)] then that would be concatenating together two column vectors horizontally, and the result would be a something-by-2 matrix. Your plot attempt A(1,:), A(2,:) would then be extracting row 1 of the matrix with 2 columns, to plot against row 2 of the matrix with 2 columns. That would draw a single line segment from (x(1),x(2)) to (y(1),y(2)) instead of the (x(1),y(1)) to (x(2),y(2)) that you would have expected.
You did not mention any error message, so that tends to suggest that your X and Y are both column vectors. In that case, what you should be doing is