Separating a structure field by unique elements?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
KSSV
el 27 de Feb. de 2019
Editada: KSSV
el 27 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Direct Search en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!