How to meet two true conditions in a single loop?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 30 Avr 2012
Please do not open duplicate questions; it leads to confusion and divided efforts. Your duplicate has been deleted.
Réponse acceptée
Thomas
le 30 Avr 2012
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!