How to compare 3 different arrays

3 views (last 30 days)
skysky2000
skysky2000 on 7 Mar 2018
Commented: Walter Roberson on 28 Mar 2018
Dear All,
I have 3 arrays as shown below (A, L1, E), First, I need to check array A, in each column the similar number and then take the location of each similar number. Then, when I found there are number same in each column , I move to array L1 and compare to locations of the similar number and take the highest location number = 1. In case if the locations in array L1 same as well, then I need to go to the array E and compare the locations of highest number and give it value 1.
A=[22 40 55 72;
33 55 32 67;
45 40 23 65;
22 40 55 45
];
L1=[3 5 60 3;
2 7 6 43;
5 5 45 56;
3 5 55 34
];
E=[0.52 0.3 0.7 0.45;
0.2 0.11 0.6 0.2;
0.1 0.32 0.45 0.33;
0.51 0.31 0.79 0.2
];
the expected results should be:
matrix=[1 0 0 1;
1 1 1 1;
1 1 1 1;
0 1 1 1
];
Help please , I have stuck with this problem since week. Please admin, I appreciate if you dont locked the question, its not part of assignment.
  1 Comment
Walter Roberson
Walter Roberson on 7 Mar 2018
In column 2, the 55 in the second row is unique, so matrix(2,2) = 1.
In column 2, the 40 in rows 1, 3, 4 are the same, so for those we have to look in column 2 row 1, 3, 4 of L1. We see 5 for all of those entries there, so we have to look in E. The corresponding entries in E are 0.3, 0.32, 0.31, the highest of which is 0.32 from row 3. So matrix(2,3) = 1. But that means that neither (2,1) nor (2,4) are highest under those rules, so matrix(2,1)=0 and matrix(2,4)=0.
That would leave us with matrix(:,2) = [0; 1; 1; 0]. But your requested output is [0; 1; 1; 1] there.
Did I misunderstand the rules, or is your expected result incorrect?

Sign in to comment.

Answers (2)

skysky2000
skysky2000 on 7 Mar 2018
Thanks Walter for your replying. in array L1 we put 0 into location of highest number , but in array E we put 0 in the miniumun valuve. so, the results as below: results = [1 1 1 0; 0 1 1 1; 0 1 1 1;1 1 1 1].
I can share the code if you like.
  4 Comments
skysky2000
skysky2000 on 8 Mar 2018
Dear Walter,
Sorry I did mistake. I need to put value 0 to the min location of array E.

Sign in to comment.


skysky2000
skysky2000 on 28 Mar 2018
?
  1 Comment
Walter Roberson
Walter Roberson on 28 Mar 2018

Just write a loop. It isn't worth spending weeks to get a nice vectorized expression. Get your code working first and then worry about vectorizing.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!