필터 지우기
필터 지우기

How to meet two true conditions in a single loop?

조회 수: 5 (최근 30일)
Lei
Lei 2012년 4월 30일
hello.everyone. I wrote a code to extract lithology depth information using strcmp function. However, this one has problem because both the two condictions in the if statement are true. And they are the two lithology I care about! i.e. After I execute the code, it ends in the first if statement cauz it is true, then it skips the second elseif statement. but i also need the second one! How can I do this? Thanks!
fid=fopen('ECC_LAS_7_Stratlogs.txt');
c=textscan(fid,'%f%f%f%s');
fclose(fid);
m=0;n=0;
for i=1:size(c{2})
if strcmp(c{4}(i),'Paskapoo-Undifferentiated')==1
m=m+1;
Paskapoo(m,1)=c{2}(i);
Paskapoo(m,2)=c{3}(i);
elseif strcmp(c{4}(i),'Scollard top')==1
n=n+1;
Scollard(n,1)=c{2}(i);
Scollard(n,2)=c{3}(i);
end
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 4월 30일
Please do not open duplicate questions; it leads to confusion and divided efforts. Your duplicate has been deleted.
Lei
Lei 2012년 4월 30일
Hi Walter,
Sorry about that! I know I made a second question, the problem is that I accpeted answer and that answer does not solve my question! and i assume that no one would look at my question again after I accepted anser! Thats why a posted a second one.

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

채택된 답변

Thomas
Thomas 2012년 4월 30일
Matlab allows you to string together multiple boolean expressions using the standard logic operators, "&" (and), ¦ (or), and ˜ (not). For example to check to see if a is less than b and at the same time b is greater than or equal to c you would use the following commands:
if (a < b) & (b >= c)
Matlab commands
end
  댓글 수: 2
Lei
Lei 2012년 4월 30일
Hi Thomas,
I can use or (|)! Sorry, I am just new to Matlab. The or works!
Thanks!
Lei
Lei 2012년 4월 30일
Hi Thomas,
This is not I want. The and or or does not work!
Actually, I wanna both of the two formation depth information.
My data looks like this:
-289240136 813.146 775.446 Drift
-289240136 775.446 770.116 Paskapoo-Undifferentiated
-289240136 775.446 770.116 Bedrock
-289240136 770.116 748.726 Scollard top
The two conditions are in different rows!
So you know any other way I could do this?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by