I can Not include my condition

조회 수: 1 (최근 30일)
Hamid
Hamid 2014년 12월 9일
댓글: Hamid 2014년 12월 10일
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
Hamid
Hamid 2014년 12월 9일
we have 4 coordinates here therefore we have 6 elements, some of them can be deleted by this condition
dpb
dpb 2014년 12월 9일
편집: dpb 2014년 12월 9일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 12월 9일
편집: Mohammad Abouali 2014년 12월 9일
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
  댓글 수: 1
Hamid
Hamid 2014년 12월 10일
you are the best,
Merci.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by