Summation of column elements of matrix A from index values of matrix B
3 次查看(过去 30 天)
显示 更早的评论
Suppose I have matrix A=3x3 and B=3x3. I sort each column of B and get index matrix I by using [C,I]=sort(B). Now I will take first column Indices of matrix I and want to sum the corresponding elements of column A pertaining to these indices. Now I will take second column index of matrix I and sum the corresponding elements of A and so on till 4th element. I want to store these 4 sum values.
E.g. A=[1 2 3;2 3 4; 4 5 6] , B=[10 13 2; 23 24 3; 21 19 21]
Now [C,I] =sort (B), then I= [1 1 1 ;3 3 2;2 2 3]. The first column of I is [1 3 2]. Now I want to sum elements of A i.e. 1st element from first column, 3rd element from 2nd column and 2nd element from 3rd column ( 1+5+4). Store this value. Then I take 2nd column of I i.e. [1 3 2]. Again repeat summation of A as stated for 1st column (1+5+4). Then I take 3rd column of I and repeat step for A for summation (1+3+6). Now I want to store these 3 summation values in D( i.e. 10 10 10).
Pls suggest code.
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!