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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:01:38+00:00 2026-06-01T14:01:38+00:00

I have a vector of values I need to add to a second vector

  • 0

I have a vector of values I need to add to a second vector at indices specified by another vector. How do I accomplish this using Octave/Matlab?

EDIT:
v1 = [1 2 3 4]

v2 = [0 0]

indices = [1 2 1 2]

output = [4 6]

The first and third elements of v1 are added to index 1 of v2, and second and fourth element of v1 are added to second element of v2.

  • 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-01T14:01:40+00:00Added an answer on June 1, 2026 at 2:01 pm

    I think this is what you mean (if you provide a small example in your question it’s easier to understand).

    You have a vector of values

    toAdd = 1:5;
    

    You have a second, bigger vector:

    bigVector = 1:10;
    

    You want to do bigVector + toAdd, where you add the elements of toAdd at specific indices into bigVector, specified by:

    indices = [1 3 5 7 9];
    

    That is, you want the output vector:

    [ bigVector(1)+toAdd(1);
      bigVector(2);
      bigVector(3)+toAdd(2);
      bigVector(4);
      bigVector(5)+toAdd(3);
      ....
     ]
    

    In that case, you can do the following:

    outputVector = bigVector;
    outputVector(indices) = bigVector(indices) + toAdd;
    

    In particular, notice the outputVector(indices) and bigVector(indices), which selects the elements of outputVector and bigVector specified by the vector indices.

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

Sidebar

Related Questions

I have a __m256d vector packed with four 64-bit floating-point values. I need to
using a binary search tree I need to add to a vector all int
I have two vectors of values and one vector of weights, and I need
I have a vector of values which include NAs. The values need to be
I have a vector containing the values 0, 1, 2 and 3. What I
I have a vector of pointers to a class. I need to call their
I have a vector of booleans. I need to set its elements from n-th
I have a vector that looks like this: mass<-c(-2, -6, -79, 31, -28, 198,
Suppose, I have a vector with following values in it id = 100 latitude
Say I have a vector with values [1,2,3,4,5,6,7,8,9,10]. I want to create a new

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.