How to select corresponding rows of a table based on selected rows of one column?
9 views (last 30 days)
I have a table in matlab containing 3379 rows and 4 columns. The below comes the first 8 rows of in question table:
as it can be seen the numbers in pagenumber columns repeated themselves (different time like 2, 3 and so on), i want to have numbers in pagenumber column without repeating (select the same number that have max area for instance for 1765 select the row 423 0/49302 6 1765. I have used the cod below but i can just select max area column and i dont know how it should be changed that all other rows correspond to the max area be selected too. ( my goal is have the rows with max area and corresponding Geo_cod and PageNumber to that area).
FID Area1 Geo_cod PageNumber
423 0/49302 6 1765
660 0/476409 0 1765
2696 0/03057 18 1765
219 0/939628 6 1766
1026 0/060377 0 1766
1854 0/325402 0 1768
2401 0/6746 6 1768
1132 0/873215 0 1769
I used the below cod:
[c,ia,ib] = unique(t1(:,4)) ;
C = zeros(length(ia),1) ;
for i = 1:length(ia)
C(i) = max(t1.Area(ib==i));
It will give me just max area like below and i dont know what geo codes these areas are belong to?
I am novice user in matlab and any help will highly appreciated.
Jon on 17 Nov 2021
Edited: Jon on 17 Nov 2021
T = readtable('sadegh.geo_cod.xlsx');
% sort the rows of table in descending order of areas
Tsrt = sortrows(T,'Area1','descend');
% find unique page numbers
% index lists first occurence of duplicate variables, but since table is sorted
% by area this will be the one with the largest area
[~,ia] = unique(Tsrt.PageNumber);
% make new table with duplicates removed only retaining rows with largest
Tnew = Tsrt(ia,:);
% sort back to have table with increasing page numbers
Tnew = sortrows(Tnew,'PageNumber');