how do i select data from a column based on another column?

Basically, I have two data columns: one with depth, the following column with its corresponding temperature. However the depth is in a random order with no sort of set intervals either.
How would I for example find all values for Temperature (column 2) for when depth (column 1) equals Zero?
Thanks, Pietro

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 11 日
編集済み: Azzi Abdelmalek 2016 年 5 月 11 日

0 投票

a=[1 2;3 4;5 0;5 1;1 0;7 8;4 0]
out=a(a(:,2)==0,:)

2 件のコメント

Pietro Dinmore
Pietro Dinmore 2016 年 5 月 11 日
thanks a lot! is there any way to loop it so that I can get separate columns for each depth?
When I attempt to loop it now, it remains within the same matrix. so basically im getting everything put in order of increasing depth.
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 11 日
You don't need a loop
c1=out(:,1)
c2=out(:,2)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by