MATLAB: I can Not include the condition

matrices

Hi everybody,
my code produce some elements with x,y,z coordinates.
I want to put a condition that make them to have z limit, for example from z 0-100 there are some elements and also from z 100-200 there are some elements and so on but there is no element that is in both z limit area.
any suggestion will may be helpful and Thank you for that.
for i = 1:ne
nodnum=zeros(1,nen);
for j = 1 : nen
check=Dof(:,1:nend)-ones(n,1)*Edof(i,(j-1)*nend+2:j*nend+1);
[indx,dum]=find(check==0);
nodnum(j)=indx(1);
end
%
Ex(i,:)=Coord(nodnum,1)';
if nsd>1
Ey(i,:)=Coord(nodnum,2)';
end
if nsd>2
Ez(i,:)=Coord(nodnum,3)';
end
Le(i)=sqrt((Ex(i,1)-Ex(i,2))^2+(Ey(i,1)-Ey(i,2))^2+(Ez(i,1)-Ez(i,2))^2);
end

Best Answer

Ok, now I get it (I think).
You have four points, and lines connected between each two points are elements. (so in case of four points you have 6 elements or 6 lines).
Now You want only those lines (elements) that the ending points have z<500 or 500<z<1000 and not both. Pretty much you want your line to stay either under 500 elevation or in 500..1000 elevation and not cross the 500.
So, the solution depends a bit on how you store the elements. Let's say you have 4 points so point 1 to 4. Something like this should work:
clear; clc; close all;
P=[ 0 0 0;
500 500 500;
500 500 1000;
500 500 1500 ];
elements=[1 2; % defining start and end point
1 3;
1 4;
2 3;
2 4;
3 4];
% this is your test function (I used <= instead of <)
testFunc=@(x) ( all(P(x,3)<=500) || ...
all(P(x,3)>=500 & P(x,3)<=1000) );
% this parts checks the condition.
elementsCell=mat2cell(elements,ones(size(elements,1),1),size(elements,2));
elementsMask=cellfun(testFunc,elementsCell);
disp('Elements satisfying the condition:')
disp(find(elementsMask))
disp('Elements end points:')
disp(elements(elementsMask,:))
Movafagh bashi
Related Question