Separating a structure field by unique elements?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
In part C of this code, I want to determine which country in each continent has the largest agricultural water withdrawl, and then display the names of the continents and country.
I know what I have is wrong, but I'm stuck on how to split a field by the unique continents, find the max of another field and then output the country related field. I know I probably need to make individual tables with data from each continent but I can't figure out how to do that either. Please help!
0 Kommentare
Antworten (1)
KSSV
am 27 Feb. 2019
Bearbeitet: KSSV
am 27 Feb. 2019
You need not to convert the Table into structure.......Table is very elegant and you can do what ever you want. Check the below code:
T1 = readtable('aquastat.csv') ;
T = T1(1:200,[2 3 5 9 13]);
T.Properties.VariableNames = {'Country' 'Continent' 'Agricultural' 'Industrial' 'Municipal'};
[continent,ia,ib] = unique(T.Continent) ; % you can use T.(2) also
N = length(continent) ;
country = cell(N,1) ;
val = zeros(N,1) ;
for i = 1:N
idx = ib==i ;
[val0,idx0] = max(T.Agricultural(idx)) ;
val(i) = val0 ;
C = T.Country(idx) ;
country(i) = C(idx0) ;
end
iwant = table(continent,country,val) ;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Direct Search finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!