开发者

Matlab selecting values based on matrix values

I am trying to make a program which maps coordinates. I am having trouble getting Matlab to select specific values based on the vector inequality. Maybe I am doing it wrong but here is my code, where g is a vector giving the global locations of the points. EL is the length of "objects" and the local coordinates are the coordinates of the points on the "objects" for a 1-D case. Then those local coordinates are reevaluated to give a value of -1 to 1 across the length of the global object. PL is the location of the objects globally.

%Get the local coordinates of the points

for g=(gp(gp>0))
    for n1=(gp(gp<EL(1,1)))
    gp1=[n1, 1];
    end;
    for x=(gp(PL((x1-1),1)<gp<PL((x1),1)));
    gp2=[(x-(EL(x1,1))),1];
    end
    for x=(g开发者_Python百科p((PL(x1,1)<=gp)));
    gp3=[((x)-(EL(x1,1))),1];
    end
    lpap=([gp1,gp2,gp3]);
    %use the local coordinates to get the natural coordinates
    for x=(gp(gp<=EL(1,1)))
    nc=[((lpap*2)/EL(1,1))-1,1];
    end
    for x=(gp(PL(x1-1,1)<gp<PL(x1,1)));
    nc1=[((lpap*2)/EL(x1,1))-1,1];
    end
    for p=(gp(PL(x1,1)<=gp));
    nc2=[((lpap*2)/EL(x1,1))-1,1];
    end
    nct=[nc,nc1,nc2]

end

Besides nct not being -1 to 1 I know something is wrong because running this gives me one constant value for the x,p, n1 variables, which should give multiple values.


I'm not sure what you're trying to do here, and I suggest reading MATLAB's documentation on flow control to get a better idea of how to program in matlab, but just to get you started...

For loops in matlab work over an array:

for n = 1:10
    % do stuff
end

To select parts of an array based on value, you would use index referencing:

a = [1 2 3 4 5 6 7 8];
a_gt_four = a(a>4);  % returns [5 6 7 8];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜