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 8567481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:53:38+00:00 2026-06-11T17:53:38+00:00

I want to sum up several vectors of different size in an array. Each

  • 0

I want to sum up several vectors of different size in an array. Each time one of the vectors drops out of my program, I want to append it to my array. Like this:

array = [array, vector];

In the end I want to let this array be the output of a function. But it gives me wrong results. Is this possible with MATLAB?

Thanks and kind regards,
Damian

  • 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-11T17:53:38+00:00Added an answer on June 11, 2026 at 5:53 pm

    Okay, given that we’re dealing with column vectors of different size, you can’t put them all in a numerical array, since a numerical array has to be rectangular. If you really wanted to put them in the numerical array, then the column length of the array will need to be the length of the longest vector, and you’ll have to pad out the shorter vectors with NaNs.

    Given this, a better solution would be, as chaohuang hinted at in the comments, to use a cell array, and store one vector in each cell. The problem is that you don’t know beforehand how many vectors there will be. The usual approach that I’m aware of for this problem is as follows (but if someone has a better idea, I’m keen to learn!):

    UpperBound = SomeLargeNumber;
    Array = cell(1, UpperBound);
    Counter = 0;
    while SomeCondition
        Counter = Counter + 1;
        if Counter > UpperBound
            error('You did not choose a large enough upper bound!');
        end
        %#Create your vector here
        Array{1, Counter} = YourVectorHere;
    
    end
    Array = Array(1, 1:Counter);
    

    In other words, choose some upper bound beforehand that you are sure you won’t go above in the loop, and then cut your cell array down to size once the loop is finished. Also, I’ve put in an error trap in case you’re choice of upper bound turns out to be too small!

    Oh, by the way, I just noted in your question the words “sum up several vectors”. Was this a figure of speech or did you actually want to perform a sum operation somewhere?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a method sum that I can call on different types,
There are several rank posts out there but I have yet to see one
I want to do a simple select with a SUM of several rows in
I have mpi program to distribute the large array amongst several processes on cluster.
I want to sum columns. In my controller def index @performance_reports = PerformanceReport.all end
I want to sum all elements of matrix in Matlab. If I had a
Crazy question...however, I want the sum of all the rows in a table for
I want to display sum of a column in a textbox when I hit
I am having a problem with my query. I want to use SUM in
I want to find the sum and count of specific values in my table.

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.