find a value and their related values in other columns

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 6 de Abr. de 2020
Editada: KALYAN ACHARJYA el 6 de Abr. de 2020
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 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 6 de Abr. de 2020
Editada: KALYAN ACHARJYA el 6 de Abr. de 2020
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 el 6 de Abr. de 2020
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by