find a value and their related values in other columns

4 ビュー (過去 30 日間)
SADRA SADEGHINEJAD
SADRA SADEGHINEJAD 2020 年 4 月 6 日
Hi, i have a matrix included some rows and columns and I want to find some certain values in the first columns then make a new matrix with them. I have tried with different ways but i couln`t reach to the solution.
example : let`s we have a matrix like this
degree cl
-3 0.01
0 0.04
+3 0.06
6 0.08
9 0.09
now I wanna find where the degree is +3 and 6 and then find their related value of Cl for them

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 4 月 6 日
編集済み: KALYAN ACHARJYA 2020 年 4 月 6 日
Let's example
mat=[-3 0.01
0 0.04
+3 0.06
6 0.08
9 0.09];
data_cl=mat(find(mat(:,1)==3 | mat(:,1)==6),2)
or you can use table for the same
  3 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 4 月 6 日
編集済み: KALYAN ACHARJYA 2020 年 4 月 6 日
Sure, use the any required logical indexing, to met the required condition, as you mentioned in the question
find(mat(:,1)==3 | mat(:,1)==6)
Gives the row index of the particular values, then you can ge the cl of respectice data in 2nd column
SADRA SADEGHINEJAD
SADRA SADEGHINEJAD 2020 年 4 月 6 日
i didn`t find solution for the following problem:
if we have large matrix and for instance we have angles like -3,0,3,6.... it is difficult and also not rational to do this way ( data_cl=mat(find(mat(:,1)==3 | mat(:,1)==6),2) )
how we can solve it? is it possible to find them by loop,if ....? actually i tried this but i have just get the last value of the loop

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by