How to select same numbers with tolerance?

1 visualización (últimos 30 días)
Shiv Karpoor
Shiv Karpoor el 13 de Abr. de 2022
Respondida: David Hill el 13 de Abr. de 2022
Hello MATLAB Community,
I am working on a code, where the code is run for more than 90,000 iterations and,
if my answer in any iteration is equal to zero or closer to zero I need to save that answer.
Note: My code does not end here, it also runs through different if statments before I get a final answer,
I need to add another if statement as mentioned above.
Since, I cannot share the actual code, here is an exmaple below:
Suppose I have a matrix X = [ 2.5,3.65,0,0.25,0.35,0.035,0.00025,1,4.65,5.85]
I need to create an if condition to store all values of zero with values after decimal point and store them in a different matrix.
like Y = [0,0.25,0.35,0.035,0.00025]
But this should be done with if condition only.
Can anyone please help me with any suggestions.
Thank you in advance!!
I really appreciate your help.
Kind regards,
Shiv

Respuesta aceptada

Matt J
Matt J el 13 de Abr. de 2022
X = [ 2.5,3.65,0,0.25,0.35,0.035,0.00025,1,4.65,5.85];
Y=X(abs(X)<1)
Y = 1×5
0 0.2500 0.3500 0.0350 0.0003

Más respuestas (2)

Enrico Gambini
Enrico Gambini el 13 de Abr. de 2022
Hi, try this:
X = [ 2.5,3.65,0,0.25,0.35,0.035,0.00025,1,4.65,5.85];
Y=X(X<1)
Y = 1×5
0 0.2500 0.3500 0.0350 0.0003

David Hill
David Hill el 13 de Abr. de 2022
X = [ 2.5,3.65,0,0.25,0.35,0.035,0.00025,1,4.65,5.85]
newMatrix=X(X<1);

Categorías

Más información sobre MATLAB 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