"Roger Stafford" wrote in message <jkavov$sef$1@newscl01ah.mathworks.com>...
> "Kevin Ellis" wrote in message <jkafsr$438$1@newscl01ah.mathworks.com>...
> > I want to create a code that will take this matrix and first find values on row 1 that are equal and then compare their values on row 2 to find which is greater and then remove the column containing the smaller value on row 2 from the matrix. .....
>        
> See if this works. I prepared it in haste.
>
> [~,p] = sort(H(2,:));
> [~,m] = unique(H(1,p),'last');
> Hnew = H(:,sort(p(m)));
>
> Roger Stafford
        
Here are some additional comments on your problem.
1. I assumed in the code I sent that columns possessing equal numbers in the first row do not have to be adjacent for there to be a deletion of the one with the least element in the second row.
2. In case both elements of a pair are repeated in two different columns, the code I sent will select the earlier one to be deleted. If you want it to be the later one, change the first sort to 'descending' and use 'first' in the 'unique' call.
3. You should realize that the 'unique' function will consider two elements unequal even if their least bits differ. Hence if numbers like 177.22469 are the result of computation, such results may look equal in displays but can nevertheless be considered unequal by 'unique'.
Roger Stafford
