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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:06:17+00:00 2026-05-18T08:06:17+00:00

I have a matrix I , and I want to accumulate in an array

  • 0

I have a matrix I, and I want to accumulate in an array A, for each value in I, an interval accordingly to those values in I lets call them i and j.

function acc(i,j)
  global A
  A(i:j) = A(i:j)+1;
end

However, passing and returning the arrays take too much time, because I execute the function many times, and it is not as simple as that example.

Is there any way of speeding it up? How can I pass an return those values without global?

  • 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-05-18T08:06:17+00:00Added an answer on May 18, 2026 at 8:06 am

    The link in the comments proposes using a nested function as a solution. If the function you’re using has use in several different places you may not want to nest in each place. It that case, I’d try to make the function modify in place.

    http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/

    function A = acc(A,i,j)
      A(i:j) = A(i:j)+1;
    end
    

    This should not need to make a copy provided you meet the requirements set forth in Loren’s blog post.

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

Sidebar

Related Questions

in this function i have a matrix of colors(each pixel can has a value
I have a matrix M(x,y). I want to apply a threshold in all values
I want to write a function to create an empty square matrix have size
I have a two dimensional array having elements of a matrix I want to
Let's say I have a matrix of values that I want to populate, that
I have a matrix of coordinates (X,Y), and I want to animate them by
I have a Matrix class and I want to pass an array to the
I have a 2D matrix and I want to take norm of each row.
I have huge matrix with a lot of missing values. I want to get
Lets said I have the matrix M = ones(3); and I want to divide

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.