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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:08:13+00:00 2026-05-23T15:08:13+00:00

I have some code that is taking a long time to run(several hours) and

  • 0

I have some code that is taking a long time to run(several hours) and I think it is because it is doing a lot of comparisons in the if statement. I would like it to run faster, does anyone have any helpful suggestions to improve the runtime? If anyone has a different idea of what is slowing the code down so I could try and fix that it would be appreciated.

xPI = zeros(1,1783);
argList2 = zeros(1,1783);
aspList2 = zeros(1,1783);
cysList2 = zeros(1,1783);
gluList2 = zeros(1,1783);
hisList2 = zeros(1,1783);
lysList2 = zeros(1,1783);
tyrList2 = zeros(1,1783);

minList= xlsread('20110627.xls','CM19:CM25');
maxList= xlsread('20110627.xls','CN19:CN25');
N = length(pIList);
for i = 1:N
    if (argList(i)>= minList(1) && argList(i) <= maxList(1)) ...
        && (aspList(i)>= minList(2) && aspList(i) <= maxList(2)) ...
        && (cysList(i)>= minList(3) && cysList(i) <= maxList(3)) ...
        && (gluList(i)>= minList(4) && gluList(i) <= maxList(4)) ...
        && (hisList(i)>= minList(5) && hisList(i) <= maxList(5)) ...
        && (lysList(i)>= minList(6) && lysList(i) <= maxList(6)) ...
        && (tyrList(i)>= minList(7) && tyrList(i) <= maxList(7))

        xPI(i) = pIList(i);
        argList2(i) = argList(i);
        aspList2(i) = aspList(i);
        cysList2(i) = cysList(i);
        gluList2(i) = gluList(i);
        hisList2(i) = hisList(i);
        lysList2(i) = lysList(i);
        tyrList2(i) = tyrList(i);
        disp('passed test');
    end
end
  • 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-23T15:08:14+00:00Added an answer on May 23, 2026 at 3:08 pm

    You can try vectorising the code; I have made up some sample data sets and duplicated some of the operations you’re performing below.

    matA1 = floor(rand(10)*1000); 
    matB1 = floor(rand(10)*1000);
    
    matA2 = zeros(10); 
    matB2 = zeros(10);
    
    minList = [10, 20]; 
    maxList = [100, 200];
    
    indicesToCopy = ( matA1 >= minList(1) ) & ( matA1 <= maxList(1) ) & ( matB1 >= minList(2) ) & ( matB1 <= maxList(2) );
    
    matA2(indicesToCopy) = matA1(indicesToCopy); 
    matB2(indicesToCopy) = matB1(indicesToCopy);
    

    No idea whether this is any faster, you’ll have to try it out.

    EDIT:
    This doesn’t matter too much since you’re only making two calls, but xlsread is horribly slow. You can speed up those calls by using this variant syntax of the function.

    num = xlsread(filename, sheet, 'range', 'basic')
    

    The catch is that the range argument is ignored and the entire sheet is read, so you’ll have to mess with indexing the result correctly.

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

Sidebar

Related Questions

I have some code that I'd like to run on a page. My problem
I have some code that at one part will get executed a lot, and
I have some functions in my Javascript code that will perform long operations such
I have some code that sets up a dictionary with some defualt values for
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have some code that is using SyncEnumerator. As you can see here ,
I have some code that inserts a list item into a list... I then
I have some code that dynamically creates a new button through JavaScript that when
I have some code that attempts to test whether my application is running with
I have some code that does MemoryStream ms = new MemoryStream(); ... return Image.FromStream(ms);

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.