Relative Ranking of position in an array

조회 수: 4 (최근 30일)
Mick Stukes
Mick Stukes 2021년 5월 6일
답변: Bruno Luong 2021년 5월 7일
Hi!
I have a large array with 10 rows of numerical data. I am trying to find an 'ordering' by size of all the elements. I turned the raw data into an indexed array through maxk:
[M10,I10]= maxk(dgoutput,10,1)
And my I10 array has the row number for the elements in order from greatest to least (1-10). It looks like this:
1 2 1 1 1 2 1 1 2
2 1 3 6 3 1 3 3 1
4 3 4 3 2 3 4 2 3
3 4 2 7 4 6 2 5 4
5 5 5 5 6 7 5 4 5
8 8 6 4 5 4 6 6 7
9 7 7 2 7 5 7 9 6
7 6 9 9 8 9 10 8 8
6 9 8 8 9 8 8 7 9
10 10 10 10 10 10 9 10 10
And I'm trying to find a way to count the occurrences when one number occurs in a higher row than another. As an example a
Count (1>2) would return 6 since there are 6 columns where 1 is above 2.
and Count(2>1) would return 3, etc.
Any help would be appreciated!

채택된 답변

David Hill
David Hill 2021년 5월 6일
If a is your matrix above.
sum(find(a==1)-find(a==2)<0);
  댓글 수: 2
Mick Stukes
Mick Stukes 2021년 5월 7일
Thanks for this! My situation is a touch more complicated than I had originally explained, and I'm struggling to adapt this method to my needs.
I am now searching through my array for columns where two specific criteria to be met:
1: the number 3 is in the first row
AND
2: the number 1 occurs in a higher row than the number 2
Currenlty I can only find it for exact placings with the code:
AI = sum(I10(1, :) == 3 & I10(2, :) == 1 & I10(3, :) == 2);
Which gives me only the total where the rows have 3, 1 and then 2.
Can you help?
Mick Stukes
Mick Stukes 2021년 5월 7일
I have tried using the find command in conjunction with the & criterion:
AI = sum(I10(1, :) == 3 & find(I10==1)-find(I10==2)<0);
but I get an error:
Requested 100000x100000 (9.3GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a
long time and cause MATLAB to become unresponsive.

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

추가 답변 (1개)

Bruno Luong
Bruno Luong 2021년 5월 7일
I10=[1 2 1 1 1 2 1 1 2
2 1 3 6 3 1 3 3 1
4 3 4 3 2 3 4 2 3
3 4 2 7 4 6 2 5 4
5 5 5 5 6 7 5 4 5
8 8 6 4 5 4 6 6 7
9 7 7 2 7 5 7 9 6
7 6 9 9 8 9 10 8 8
6 9 8 8 9 8 8 7 9
10 10 10 10 10 10 9 10 10];
[r1,~]=find(I10==1);
[r2,~]=find(I10==2);
count1gt2 = sum(r1<r2)
count1gt2 = 6
count2lt1 = sum(r2<r1)
count2lt1 = 3

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by