compare values and eliminate

hi,
i have two matrices of same dimensions 2xm. for example-
A=[a1 b1 c1 d1; a2 b2 c2 d2]
B=[a1' b1' c1' d1'; a2' b2' c2' d2']
now i want to have for example a1'+a2' and compare the value with the summed values of b1+b2, c1+c2 and d1+d2 individually.
if a1'+a2' is greater than for example c1+c2 and d1+d2, then i would like to delete the elements c1&c2,d1&d2 from the matrix A and also elements c1'&c2',d1'&d2'. because the elements of matrix B correspond to the elements of matrix A ( i do some calculation using each column {meaning b1&b2 together} of matrix A and the corresponding result is saved in the respective position in matrix B as elements b1'&b2').
and i would like to repeat this process for each pair (b1'&b2', c1'&c2', d1'&d2') and compare them with all the other columns of matrix A except for the one to which it corresponds either in a loop or some other way.
and get the final result as matrix A and B, where only the highest pairs will exist after all the comparisons are done.

6 Comments

So, you're just looking for max column in A matrix, and corresponding column in B matrix?
because the elements of matrix B correspond to the elements of matrix A you mean A and B are equal/ same?
no, matrix A and B are not the same in terms of numerical value, dimension wise they are same. i take a column from matrix A, do some calculation and i store the result in matrix B in the respective column.
@Bob Nbob- no. i want to take the summed value of a column from matrix A and then compare it with the summed values of all the columns (except the one to it corresponds) from matrix B. if found to be greater, then i delete those columns from matrix B and also their corresponding columns from matrix A as well.
and i would like to do it in turn for all the columns of matrix A unless they get deleted due to the process mentioned in the previous paragraph.
deleted means, it becomes 0, yes?
@KALYAN ACHARJYA- no , deleted means the entire column will be removed, meaning the the dimension will become from 2xm to 2xm-1.
making it 0 means that the dimension stays the same as 2xm.

Sign in to comment.

Answers (1)

% You can change the value of m, here I am considering 4
a=randi(2,4);
b=randi(2,4);
[rows colm]=size(a);
for i=1:colm-1
sum_a=sum(a(1,i),a(2,i));
sub_b=sum(b(1,i+1),b(2,i+1));
if sum_a>sub_b
a(1,i)=0; a(2,i)=0;
b(1,i+1)=0; b(2,i+1)=0;
end
end

1 Comment

i am sorry, but a summed value from matrix a need to compared with all the summed values of matrix b. correct me if i am wrong, here it is not happening. and also i do not want them to be set to 0. i want them deleted.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!