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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:32:37+00:00 2026-05-20T03:32:37+00:00

I want to sort an array of numbers based on how large they are.

  • 0

I want to sort an array of numbers based on how large they are.

I want to run a loop using the values of an array so that it iterates each value individually. I will try to get it into somekind of psuedo code. I havent programmed in 3 years.

PL=(3,5,7,9,10);
EL=(3,2,2,2,1);

n=input;
x=array;
gp=2.5*(1:n)

% I want this to run for each value of PL seperately
for each PL_i in PL

    x=(EL(1,1) < gp <= PL); 
    % ...and then the vector x subtracted from each value of EL 
    gp2=(x-(EL);
    % ...and then put those values from gp2 back into an array 

end

Thanks for helping anyone I have worked on this program many hours. This step would greatly aid the entire project.

I can accomplish this using multiple if loops….

g=(gp(gp>0));
gp1=(gp(gp<=EL(1,1)));
if x1>=2
x=(gp((EL(2,1)<gp)));
pp=(gp(gp<=PL(2,1)));
gp2=[x,pp];
gpp2=(x-(EL(2,1)));
lpap=([gp1,gpp2]);
end
if x1>=3
x=(gp((EL(3,1)<gp)));
pp=(gp(gp<=PL(3,1)));
gp2=[x,pp];
gpp3=(x-(EL(3,1)));
lpap=([gp1,gpp2,gpp3]);
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-20T03:32:38+00:00Added an answer on May 20, 2026 at 3:32 am

    Alright so I got it, I ended up changing how I wrote the program.

    %Number of nodes and elements are entered.
    NN=input('Enter the number of elements: ');
    if NN <0;
        reply = 'Please enter more than 0 for the number of elements: ';
        NN=input('Number of Elements?:');
    end
    % prompt for length of elements also define the global length and total
    % length 
    for  x1=1:NN;
        EL(x1)=input(['Enter the length of element ', num2str(x1) ': ']);
        PL(x1)=tlength;
        tlength=tlength+EL(x1);
        PL(NN+1)=tlength;
    end
    %Enter the number of output points
    npoints=input('Enter the number of desired output points: ' );
    %Establish what order the elements are.
    Order=input('Enter the order of the elements (1, 2, 3): ');
    %Determine the spacing of the points
    spacepoints=tlength/(npoints);
    %Determine the global coordinate of the points
    gp=(1:spacepoints:PL(NN));
    %Get the local coordinates of the points
    for c=1:1:npoints;
        for i=1:1:NN;
            if ((c-1)*spacepoints)<=PL(i+1) && ((c-1)*spacepoints)>=PL(i);
                local(c)=((c)*spacepoints)-PL(i); 
    
            end
            if ((c-1)*spacepoints)>=PL(NN);
                local(c)=((c)*spacepoints)-PL(NN);
                element(i)=NN;
            end
    
        end
    end
    %Get the natural coordinates from the local coordinates
    for c=1:1:npoints;
        for i=1:1:NN;
            if ((c-1)*spacepoints)<PL(i+1) && ((c)*spacepoints)>PL(i);
                nc(c)=((2*local(c))/EL(i))-1;
            end
            if ((c-1)*spacepoints)>PL(NN);
                nc(c)=((2*local(c))/EL(NN))-1;
            end
        end
    end
    %Input for the nodal values
     for i=1:1:((Order*NN)+1)
    
      values(i)=input(['Enter the nodal value' num2str(i) ': ']);
    
     end
    %To find the value for linear
    if Order==1
      for i=1:1:NN;
          for c=1:1:npoints;
              if ((c-1)*spacepoints)<=PL(i+1) && ((c)*spacepoints)>=PL(i);
                  si(c)=1/2*(1-nc(c));
                  sj(c)=1/2*(1+nc(c));
                  V(c)=si(c)*values(i)+sj(c)*values(i+1);
              end
              if ((c-1)*spacepoints)>=PL(NN);
                  si(c)=1/2*(1-nc(c));
                  sj(c)=1/2*(1+nc(c));
                  V(c)=si(c)*values(i)+sj(c)*values(i+1);
              end
          end
      end
    end    
    %To find the value for a quadratic
    if Order==2;
        for i=1:1:NN;
         for c=1:1:npoints;
         if ((c-1)*spacepoints)<PL(i+1) && ((c)*spacepoints)>PL(i);
         si(c)=(-1/2)*nc(c)*(1-nc(c));
         sk(c)=(1/2)*nc(c)*(1+nc(c));
         sj(c)=(1-nc(c))*(1+nc(c));
         V(c)=si(c)*values(2*i-1)+sj(c)*values(2*i)+sk(c)*values(2*i+1)
         end
         if ((c-1)*spacepoints)>PL(NN);
         si(c)=(-1/2)*nc(c)*(1-nc(c));
         sk(c)=(1/2)*nc(c)*(1+nc(c));
         sj(c)=(1-nc(c))*(1+nc(c));
         V(c)=si(c)*values(i*2-1)+sj(c)*values(i*2)+sk(c)*values((i*2)+1);
         end
         end 
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input file that I want to sort based on timestamp which
I have a linked list that I want to sort part of, eg: std::sort(someIterator,
I have a list of Python objects that I want to sort by a
I have a file temp.txt, that I want to sort with the sort command
Using NHibernate ICriteria and adding .AddOrder ... I want to sort by a property
Let's say I have an array of n elements(numbers or words), I want to
I have a huge tab separated file which I want to sort on its
Given a list of strings, I want to sort it alphabetically and remove duplicates.
I have a list of input words separated by comma. I want to sort
I have several std::vector , all of the same length. I want to sort

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.