find a value and their related values in other columns

4 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by