单独评估数组中的点

时间:2011-02-15 22:35:56

标签: matlab

我想根据它们的大小对数组进行排序。

我想使用数组的值运行循环,以便它单独迭代每个值。我会尝试将它变成某种伪代码。我在3年内没有编程。

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

感谢您帮助我在这个项目上工作了很长时间。这一步将极大地帮助整个项目。

我可以使用多个if循环来完成这个....

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 个答案:

答案 0 :(得分:0)

好吧,所以我明白了,我最后改变了我编写程序的方式。

%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