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.
0 Comments
Sign in to comment.