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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:14:10+00:00 2026-06-14T23:14:10+00:00

I have the array a=1:20 and a series of indices which indicate where I

  • 0

I have the array

a=1:20

and a series of indices which indicate where I want to start pulling data out:

i=[4,12]

For each index i, I want that index and the next four (well, x, really) elements in a column or row. I’ll avoid getting to close to the end of the array, so that special case can be disregarded.

If I was hard-coding this, I could use:

a([4:8;12:16])

and this would achieve my result.

But i may have many different values.

Any thoughts on how I can transform a list of indices into a matrix of ranges, or other ways to solve this problem?

EDIT
I am using Matlab 2007; it would be preferable if the solution relied solely on Matlab’s internals and toolboxes. bsxfun is not present until 2007a.

  • 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-14T23:14:11+00:00Added an answer on June 14, 2026 at 11:14 pm

    Let i be your indicesx and x the number of elements you want in addition to the elements in i, then you can use

    i = [4 6 8];
    x = 4; 
    
    bsxfun(@plus, 0:x, i(:)) 
    

    to get a matrix of indices:

    ans =
    
         4     5     6     7     8
         6     7     8     9    10
         8     9    10    11    12
    

    If you do not have access to bsxfun you can use repmat instead:

    i = [4 6 8];
    x = 4; 
    
    repmat(i(:), 1, x+1) + repmat(0:x, length(i), 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of array formulas in Excel that key off of each
Hello I have a 1000 data series with 1500 points in each. They form
I have an array with series of objects and I want to search through
I have an array which contains serialized data similar to the example below. Array
In my program, I have created an NSMutable Array which contains a series of
I have an array of numbers and I want to find the first series
I have a series of label elements that I want to sort by their
I have a 3D array which has a time-series of air-sea carbon flux for
Suppose I have an array A. I have a series of index pairs (a1,
In my program, I have a series of UIButtons in an array that I

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.