compare values and eliminate
Afficher commentaires plus anciens
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 commentaires
Bob Thompson
le 14 Mai 2018
So, you're just looking for max column in A matrix, and corresponding column in B matrix?
KSSV
le 15 Mai 2018
because the elements of matrix B correspond to the elements of matrix A you mean A and B are equal/ same?
Muhammad Ridwanur Rahim
le 15 Mai 2018
Muhammad Ridwanur Rahim
le 15 Mai 2018
KALYAN ACHARJYA
le 15 Mai 2018
deleted means, it becomes 0, yes?
Muhammad Ridwanur Rahim
le 15 Mai 2018
Réponses (1)
KALYAN ACHARJYA
le 15 Mai 2018
% 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
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!