How to use the unique command in a loop and how to filter data?

3 visualizzazioni (ultimi 30 giorni)
I have a table of data for the year 2001, i need goals less than or equal to 12 and then to count the number of different teams that only fit in this category (have never scored higher than 12 goals in 2001), so far:
t= length(unique(guest_team(i)));
y=0
for i=1:games;
if 2001==year(i) & t & 12>=guest_goals(i) ;
y=y+1;
end
end
however, this just gives me the number of instances any team scores less than or equal to 12, any help would be greatly appreciated thanks!

Risposte (1)

TastyPastry
TastyPastry il 21 Ott 2015
If your data is organized something like:
Year Team Goals
2001 1 14
2001 2 12
2002 3 8
2003 1 9
2002 1 16
...
Where Year, Team and Score are separate vectors but each index corresponds to a game, then
numTeams = numel(unique(guest_team(year == 2001 && guest_goals <= 12)));
You're looking for games in 2001, goals less than 12. That creates your mask for guest_team. Then, the output of unique() will only find one instance of each team, numel() finds how many teams there are.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by