Not sure how to do this and it’s really driving me crazy.
I have a large matrix with 3 columns showing:
- The number of items sold in the year
- The first year the items were sold
- The last year the items were sold.
So in the following example, 13 items were sold each year between 2000-2010 and 44 in 2003 and 2004:
Matrix_A = {13, 2000, 2010;
44, 2003, 2004}
I’m trying to separate out the values by year to calculate the total number of items sold each year. So, 57 (13 + 44) items will have been sold in 2003 and 2004, and 13 all other years.
The resulting matrix would look like this:
{13, 2000;
13, 2001;
13, 2002;
13, 2003;
13, 2004;
13, 2005;
13, 2006;
13, 2007;
13, 2008;
13, 2009;
13, 2010;
44, 2003;
44, 2004}
I’ve tried creating a separate empty matrix for each year, looping through Matrix_A and assigning the row to the appropriate annual matrix. So, for Matrix_A:
- 13 will be added to the matrixes for 2000 to 2010 and,
- 44 to the matrices for 2003 and 2004.
But this seems to involve dynamic variable names, which I can’t implement.
In all, I’m lost. Any ideas?
Thanks!
Here is a simple loop over the datasets that generates the matrix you showed in the question