Question about logical indexing
I am relatively new to MatLab and am having a tough time with organizing a set of data for work. I have the data in two separate tables. The first table is a master list of traps and cumulative catch per trap with variable names: Year (using integers in place of actual years), Site (again, integers instead of site names), Week (integers again), Trap (integer – unique Tag ID), Catch (response measured – count data). Example below:
Year Site Week Trap Catch
____ ____ ____ ____ _____
1 1 1 29 9
1 1 1 28 0
1 1 1 18 4
1 1 1 27 0
1 1 1 622 19
1 1 1 10 0
1 1 1 17 10
The second table is the raw data describing each individual animal collected in each trap. Example with variable names below:
Year Week Site Trap Sex CL Legal Greater60
____ ____ ____ ____ ___ ____ _____ _________
1 1 2 41 2 71.1 0 1
1 1 2 41 2 50 0 0
1 1 2 42 2 73.9 0 1
1 1 2 42 2 57.3 0 0
1 1 2 42 2 61.5 0 1
Year, Week, Site, and Trap all appear in both tables. In table two. Catch, in table 1 is the total number of animals caught by each unique trap in a year, week, site combination. Legal and Greater60 in table two are binary responses based on the size of the animal (1 = true, 0 = false). All traps in Table two appear in table one, but if a trap did not catch anything, it does not appear in table two.
My goal is to use logical indexing to add two columns (Legal, Greater60) to Table 1 after Catch wherein I have a sum of the Legal and Greater60 values in Table two for each trap in each year, week, site combination.
I hope that makes sense. Any help is much appreciated.I am relatively new to MatLab and am having a tough time with organizing a set of data for work. I have the data in two separate tables. The first table is a master list of traps and cumulative catch per trap with variable names: Year (using integers in place of actual years), Site (again, integers instead of site names), Week (integers again), Trap (integer – unique Tag ID), Catch (response measured – count data). Example below:
Year Site Week Trap Catch
____ ____ ____ ____ _____
1 1 1 29 9
1 1 1 28 0
1 1 1 18 4
1 1 1 27 0
1 1 1 622 19
1 1 1 10 0
1 1 1 17 10
The second table is the raw data describing each individual animal collected in each trap. Example with variable names below:
Year Week Site Trap Sex CL Legal Greater60
____ ____ ____ ____ ___ ____ _____ _________
1 1 2 41 2 71.1 0 1
1 1 2 41 2 50 0 0
1 1 2 42 2 73.9 0 1
1 1 2 42 2 57.3 0 0
1 1 2 42 2 61.5 0 1
Year, Week, Site, and Trap all appear in both tables. In table two. Catch, in table 1 is the total number of animals caught by each unique trap in a year, week, site combination. Legal and Greater60 in table two are binary responses based on the size of the animal (1 = true, 0 = false). All traps in Table two appear in table one, but if a trap did not catch anything, it does not appear in table two.
My goal is to use logical indexing to add two columns (Legal, Greater60) to Table 1 after Catch wherein I have a sum of the Legal and Greater60 values in Table two for each trap in each year, week, site combination.
I hope that makes sense. Any help is much appreciated. I am relatively new to MatLab and am having a tough time with organizing a set of data for work. I have the data in two separate tables. The first table is a master list of traps and cumulative catch per trap with variable names: Year (using integers in place of actual years), Site (again, integers instead of site names), Week (integers again), Trap (integer – unique Tag ID), Catch (response measured – count data). Example below:
Year Site Week Trap Catch
____ ____ ____ ____ _____
1 1 1 29 9
1 1 1 28 0
1 1 1 18 4
1 1 1 27 0
1 1 1 622 19
1 1 1 10 0
1 1 1 17 10
The second table is the raw data describing each individual animal collected in each trap. Example with variable names below:
Year Week Site Trap Sex CL Legal Greater60
____ ____ ____ ____ ___ ____ _____ _________
1 1 2 41 2 71.1 0 1
1 1 2 41 2 50 0 0
1 1 2 42 2 73.9 0 1
1 1 2 42 2 57.3 0 0
1 1 2 42 2 61.5 0 1
Year, Week, Site, and Trap all appear in both tables. In table two. Catch, in table 1 is the total number of animals caught by each unique trap in a year, week, site combination. Legal and Greater60 in table two are binary responses based on the size of the animal (1 = true, 0 = false). All traps in Table two appear in table one, but if a trap did not catch anything, it does not appear in table two.
My goal is to use logical indexing to add two columns (Legal, Greater60) to Table 1 after Catch wherein I have a sum of the Legal and Greater60 values in Table two for each trap in each year, week, site combination.
I hope that makes sense. Any help is much appreciated. logical indexing, data organization MATLAB Answers — New Questions