one-to-one mapping of a vector based on error bounds

1 vue (au cours des 30 derniers jours)
Jonah Foley
Jonah Foley le 26 Mar 2020
lets say I have the vector x = [-13, -13.2, -13.7, -11.6, -8.7, -6,5, -6.7, -6.6, -6.2, -5.9]
and I would like to make the following mappings, based upon some error bounds (i.e cleaning up the data):
-14 < x < -8 --> x = -13
-8 < x < -2 --> x = -6
so that under the mapping x becomes:
x = [-13, -13, -13, -13, -13, -6, -6, -6, -6, -6]
I have been able to achieve this using a for loop, but I'm assuming there is a faster/more efficient way to do this. Any ideas? Thanks

Réponses (1)

David Goodmanson
David Goodmanson le 30 Mar 2020
Modifié(e) : David Goodmanson le 30 Mar 2020
Hi Jonah,
x(-14 < x & x < -8) = -13;
x(-8 < x & x < -2) = -6;
What happens if x =8? Looks like you could use <= in place of one of the two <

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by