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!