I can Not include my condition

1 view (last 30 days)
Hamid
Hamid on 9 Dec 2014
Commented: Hamid on 10 Dec 2014
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
  5 Comments
Hamid
Hamid on 9 Dec 2014
we have 4 coordinates here therefore we have 6 elements, some of them can be deleted by this condition
dpb
dpb on 9 Dec 2014
Edited: dpb on 9 Dec 2014
Need more precise illustration of the dataset as it's stored and what it is you're actually asking for. Give a small sample that illustrates both the full input and the desired output.
We know you understand what your explanation means but we don't have the insider's knowledge to be able to read between the lines beyond what is actually provided here.

Sign in to comment.

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 9 Dec 2014
Edited: Mohammad Abouali on 9 Dec 2014
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

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!