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
Bob Thompson 2018년 5월 14일
So, you're just looking for max column in A matrix, and corresponding column in B matrix?
KSSV
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
Muhammad Ridwanur Rahim 2018년 5월 15일
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.
Muhammad Ridwanur Rahim
Muhammad Ridwanur Rahim 2018년 5월 15일
@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.
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 5월 15일
deleted means, it becomes 0, yes?
Muhammad Ridwanur Rahim
Muhammad Ridwanur Rahim 2018년 5월 15일
@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.

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 5월 15일

0 개 추천

% 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

Muhammad Ridwanur Rahim
Muhammad Ridwanur Rahim 2018년 5월 15일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 5월 14일

댓글:

2018년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by