Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:08:25+00:00 2026-06-13T21:08:25+00:00

Not sure how to do this and it’s really driving me crazy. I have

  • 0

Not sure how to do this and it’s really driving me crazy.
I have a large matrix with 3 columns showing:

  1. The number of items sold in the year
  2. The first year the items were sold
  3. 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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:08:26+00:00Added an answer on June 13, 2026 at 9:08 pm

    Here is a simple loop over the datasets that generates the matrix you showed in the question

    B = [];
    A = [13,    2000,    2010;
         44,    2003,    2004];
    
    for i=1:size(A,1)
        years = [A(i,2):A(i,3)]';
        start = size(B, 1);
        B(start+1:start+numel(years),2) = years;
        B(start+1:start+numel(years),1) = A(i,1);
    end
    B =
    
          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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure this is really bubbling, I will explain. I have this:
I am not sure this is possible. I have a bunch of @Helper 's
I'm not sure this is a Prototype specific issue, but since I don't have
I'm not sure this is the right place but here I go: I have
I'm not sure this is even possible, but here goes: I have a class
I am not sure if this is the best approach but I have a
Not sure this is possible but maybe you can help. I have a list,
I'm not sure this is even possible, but I would really like to be
I am sure this is really simple, but I'm not sure even how to
Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.