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 件のコメント
Bob Thompson
2018 年 5 月 14 日
So, you're just looking for max column in A matrix, and corresponding column in B matrix?
KSSV
2018 年 5 月 15 日
because the elements of matrix B correspond to the elements of matrix A you mean A and B are equal/ same?
Muhammad Ridwanur Rahim
2018 年 5 月 15 日
Muhammad Ridwanur Rahim
2018 年 5 月 15 日
KALYAN ACHARJYA
2018 年 5 月 15 日
deleted means, it becomes 0, yes?
Muhammad Ridwanur Rahim
2018 年 5 月 15 日
回答 (1 件)
KALYAN ACHARJYA
2018 年 5 月 15 日
% 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
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!