MATLAB: How to find vectors that are multiple of other vectors inside a matrix

matrix manipulationmultipleperformancescalarvector

For example, given following matrix:
F = [0 1 2; 1 2 3; 0 2 4; 5 6 8; 2 4 6];
0 1 2
1 2 3
0 2 4
5 6 8
2 4 6
Wrong:Identify the rows that are (integer) multiples of some previous rows in the matrix.
In this case 3rd row and 5th row are multiple respectively of 1st and 2nd rows.
  • I want to copy the identified rows and create a new matrix out of it.
  • Delete the identified rows from the original matrix.
Edit:
Correct: The matrix is composed by integers, each element correspond to a part in weight of a substance so what matters is the proportion, the objective is to delete from the original matrix all the rows that have same proportion of elements. Doesn't matter rows order.
Inside the matrix we could find N rows that are multiple of others, I have to eliminate all of them except one the one that is multiple of 1.
So if I have two rows like this (I made them consecutive to simplify):
2 4 6
1 2 3
I should eliminate one of them, better in this case to delete first row so I can keep the row which is multiplied by one.

Best Answer

This is way easier than it has been made to be.
F = [0 1 2; 1 2 3; 0 2 4; 5 6 8; 2 4 6];
Assuming you have a recent release of MATLAB, do this:
Fscale = F./max(abs(F),[],2)
Fscale =
0 0.5 1
0.333333333333333 0.666666666666667 1
0 0.5 1
0.625 0.75 1
0.333333333333333 0.666666666666667 1
That scales the elements of F such that the MAXIMUM absolute element in any row is 1.
An older MATLAB release would have you write it as:
Fscale = bsxfun(@rdivide,F,max(abs(F),[],2));
Now, just look for replicate rows. uniquetol will suffice to solve the problem now.
[UniqF,I,J] = uniquetol(Fscale,10*eps,'byrows',true)
UniqF =
0 0.5 1
0.333333333333333 0.666666666666667 1
0.625 0.75 1
I =
1
2
4
J =
1
2
1
3
2
So these rows of F were scaled versions of some other row:
Frep = F;
Frep(I,:) = []
Frep =
0 2 4
2 4 6
We can look at the vector J to see that rows 1 and 3, and rows 2 and 5 appear twice. Those rows were multiples of each other. I suppose you could go further, and verify if the multiplier was an INTEGER factor easily enough. I don't know your real goal in this. Is it homework? If so, then they might slip in a row that is a factor of 2.5 times another, just to test your code.
If you want to discard all rows with a multiplier greater than 1? We can find ways to do that too.