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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:33:11+00:00 2026-06-15T11:33:11+00:00

To begin, this problem is easily solvable with a for-loop. However, I’m trying to

  • 0

To begin, this problem is easily solvable with a for-loop. However, I’m trying to force/teach myself to think vector-wise to take advantage of what Matlab does best.

Simplified, here is the problem explanation:

  • I have a vector with data in it.
  • I have a 2xN array of start/stop indices that represent ranges of interesting data in the vector.
  • I want to perform calculations on each of those ranges, resulting in a number (N results, corresponding to each start/stop range.)

In code, here’s a pseudoexample of what I’d like to have at the end:

A = 1:10000;
startIndicies = [5 100 1000];
stopIndicies = [10 200 5000];
...
calculatedResults = [func(A(5:10)) func(A(100:200)) func(A(1000:5000))]

The length of A, and of the start/stop index array is variable.

Like I said, I can easily solve this with a for loop. However since could be used with a large data set, I’d like to know if there’s a good solution without a for loop.

  • 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-15T11:33:13+00:00Added an answer on June 15, 2026 at 11:33 am

    Here is one possible solution, although, I won’t call it a fully vectorized solution, rather a one liner one.

     out = cellfun(@(i,j) fun(A(i:j)), num2cell(startIndicies), num2cell(stopIndicies) );
    

    or, if you plan to have homogeneous outputs,

     out = arrayfun(@(i,j) fun(A(i:j)), startIndicies, stopIndicies);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is baffling me: BEGIN; INSERT INTO sub_users(user_id, email) SELECT user_id FROM users
This is my problem - shortly: var c1:TClass1; c2:TClass2; begin c1 := c1.Create; c2
Please help this problem. I have this command: awk 'BEGIN {printf %-15s, Date of
This problem came up when trying out the Unit Testing capabilities of SQLDeveloper. When
I have a LaTeX table that looks like this: \begin{table}[!ht] \centering \small \caption{ \bf{Caption}}
Alright so I have no idea how to even begin doing this But basically
Given this : delimiter // create procedure setup() begin declare d datetime; set d
This is the instruction I use: BEGIN DBMS_SCHEDULER.RUN_JOB(25950); commit; END; And this is the
Let me begin by saying I realize this isn't the best idea from an
To clarify before I begin, this is NOT homework but rather I am studying

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.