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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:22:32+00:00 2026-05-26T23:22:32+00:00

I am finding that a lot of time spent in my matlab function is

  • 0

I am finding that a lot of time spent in my matlab function is in this code:

intersect(freq_bins, our_bins);

Both can be rather large vectors, and are comprised of only integers. I just need to know which integers are in both. This is truly the primitive purpose of intersect(), so I suspect that the answer is: it doesn’t get any better. But maybe someone has some suggestions.

  • 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-26T23:22:32+00:00Added an answer on May 26, 2026 at 11:22 pm

    intersect calls ismember. In your case, you don’t need all the complicated checks that intersect does, so you can save some overhead and call ismember directly (note: I made sure to call both functions before timing them):

    a = randi(1000,100,1);
    b = randi(1000,100,1);
    
    >> tic,intersect(a,b),toc
    ans =
        76
       338
       490
       548
       550
       801
       914
       930
    Elapsed time is 0.027104 seconds.
    
    >> tic,a(ismember(a,b)),toc
    ans =
       914
       801
       490
       548
       930
       550
        76
       338
    Elapsed time is 0.000613 seconds.
    

    You can make this even faster by calling ismembc, the function that does the actual testing, directly. Note that ismembc requires sorted arrays (so you can drop the sort if your input is sorted already!)

    tic,a=sort(a);b=sort(b);a(ismembc(a,b)),toc
    ans =
        76
       338
       490
       548
       550
       801
       914
       930
    Elapsed time is 0.000473 seconds.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am actually finding that chkContactType.Items is empty when I step through the code.
I'm finding that the code that I write in my controllers is largely repetitive
I lost a lot of time on this one, so I'm posting the question
After spending a lot of time and code on programming in Swing, I thought
I've spent a lot of time developing an operating system and working on my
Despite finding many other such questions and spending a lot of time on them,
I'm finding that with dynamic linking, even with SxS, Windows Update will come along
I'm finding that when I link an executable against a static library (.a), the
I'm finding that std::sort is very slow with sorting only 1000 items. In class
Am using Math.round and I am finding that it will not return me any

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.