MATLAB: How to remove columns or rows that are identical

columnsdeletematrix manipulationoperating on columnsrows

At first, I underestimated this by thinking that there was an easy solution and there may be but I wasn't able to find it due to my inexperience as a MATLAB user. After spending hours looking for a solution, trying various things such as taking advantage of the find command or using set operation to even using unique, it was all to no avail. I would greatly appreciate the help.
Lets say I have two randomly generated vectors with equal size or length, suppose the elements a through f are numbers that are in the reals:
x = [a b c c]; % Note: The Unique command would not help here, because a and b may also be equal to c.
y = [e f d d]; % Note: These two are always equal in size, but aren't constrained to only having 4 elements.
% These vectors aren't necessarily randomly generated, but to me, they might as well be because I have no idea what they have unless I go in to look.
The goal is to make a 2 x n matrix out of those two:
h = [x;y]; % In this case, it would result in a 2x4 matrix which two columns that are identical to each other.
In essense:
% Make it go from:
h = [a b c c; e f d d];
% To
h = [a b; e f]; % Note: The resulting matrix will always be a 2xn matrix. In other words, it is not constrained to become 2x2.
This modified matrix would then be compared to another matrix that has unique columns with the isequal command.
I will be working on this for some time, because this is a crucial step to what I was working on, so if I come across a solution, I will post it here.
Thank you,
Farruh.
Edit 1: Please assume that the identical columns are not adjacent, such as
h = [a b c b; b d f d];
Edit 2: An alternative would be to remove columns with identical indices, such as
h = [a b c d; a e c f]; % To make h = [b c d; e c f]

Best Answer

h = randi(2,2,20)
% remove columns that are consecutively repeated
lgt = diff(find([true, any(diff(h,1,2)~=0,1), true]));
h = h(:,repelem(lgt==1,lgt))