Table manipulation of matrix
이전 댓글 표시
Hi
I want to a code that will compute group each c1/c2 for each column using K = to any number
Assuming I have n = numbers length
In my case I have 1,200 columns
And 1,200 rows
For instance, if K = 2
For each columns
The sum lowest c1 + c1 / the sum lowest c2 + c2
And it goes down the column for the next lowest c1 + c1/c2 + c2 till the end
If K = 3
Same the lowest c1 + c1 + c1/ the lowest c2 + c2 + c2
And it goes down the column for the next lowest c1 + c1 + c1/c2 + c2 + c2 till the end
I have been trying to work this out using the code below but but not getting it right. It is supposed to give me multiple answers for each column depending on K
c1 = sort(J(1:2:end,:));
size(c1)
c2 = sort(J(2:2:end,:));
size(c2
f = sum (c1(1: K, :));
size(f)
c = sum (c2(1: K,: ));
size(c)
s1 = (f/c);
for instance find the data below
A B C D E F G Class
1 1 1 0 1 1 1 c1
2 2 1 2 1 0 1 c2
1 1 1 1 2 1 1 c1
2 1 1 1 1 1 1 c2
2 2 0 0 0 0 0 c1
1 1 1 1 1 1 1 c2
1 1 1 1 1 1 1 c1
1 0 0 1 1 1 1 c2
Lets do column 1
First Sorting
1 c1
1 c1
1 c1
1 c2
1 c2
2 c1
2 c2
2 c2
K = 2
The lowest c1 + c1/ The lowest c2 + c2
For column A
1+1/1+1 = 2/2 = 1
The next lowest c1 + c1/The next lowest c2 + c2
1 + 2 / 2+2 = 3/2 = 1.5
So column 1 will be
1
1.5
Thanks for your help in advance
Tino
Find my code again
c1 = sort(J(1:2:end,:));
size(c1)
c2 = sort(J(2:2:end,:));
size(c2
f = sum (c1(1: K, :));
size(f)
c = sum (c2(1: K,: ));
size(c)
s1 = (f/c);
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!