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

2 次查看(过去 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