How can I use a for loop to select values from a table that meet two conditions?

조회 수: 1 (최근 30일)
My table is tab=table(metabolites, aerobic, anaerobic).
I am trying to compute a for loop that only selects those metabolites where they are >=0 in each aerobic and anaerobic columns and where they also different value in each column for each row.
I am not too sure how I can change the below for loop to say the above, as it is currently wrong. I would be grateful for any suggestions please. Thank-you
m=1
for i=1:height(tab)
if(Aerobic(i)~=Anaerobic(i)) &
(Aerobic(i) & Anaerobic(i) >=0)
secmet(m, 1:3)=tab(i, 1:3)
m=m+1
else
continue;
end
end

채택된 답변

Chuguang Pan
Chuguang Pan 2019년 12월 13일
m=1;
for i=1:height(tab)
if(Aerobic(i)~=Anaerobic(i)) && Aerobic(i)>=0 && Anaerobic(i)>=0
secmet(m, 1:3)=tab(i, 1:3)
m=m+1
else
continue;
end
end
Just need to change the logical expresssion

추가 답변 (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