Borrar filtros
Borrar filtros

extract specific values in a matrix

3 visualizaciones (últimos 30 días)
mehra
mehra el 28 de Ag. de 2019
Comentada: the cyclist el 28 de Ag. de 2019
Hello
I have a 104*14 matrix and I need to get some of the values in column 10 of this matrix which corresponds to values in first column that equal to 0.03.
How can I write that in matlab?
Thanks

Respuesta aceptada

the cyclist
the cyclist el 28 de Ag. de 2019
Editada: the cyclist el 28 de Ag. de 2019
If A is your matrix:
A(find(A(:,10)==0.03,1),10);
You might need to be careful about getting an exact match with the floating-point value 0.03, and use some kind of tolerance instead.
For example:
A(find(A(:,10)>(0.03-1.e-9) & A(:,10)<(0.03+1.e-9),1),10);
Take a look at this documentation for eps (floating point relative accuracy) if you need to be more precise.
  2 comentarios
mehra
mehra el 28 de Ag. de 2019
Editada: mehra el 28 de Ag. de 2019
I rewrite that code as
results(results(:,1)==0.03,10)
and it worked. Thanks
the cyclist
the cyclist el 28 de Ag. de 2019
Oh, sorry, I misread! I thought you needed the first value in column 10, rather than using the value from the first column. Glad to have helped despite my error.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by