How can I make a categorical variable based on a simple rule for a numeric variable?

Unfortunately all my searching hasn't led me this very simple problem.
I want to make a new binary variable "y" that is 0 for values of "yraw" that are <12, and "1" for values that are >12.
How can I do this?

 Accepted Answer

You don't define how the rule works when y == 12. I made a choice for you.
y = double(yraw >= 12);
You don't really need to use double there, but depending on what you will do with the variable y, some operations will require that y be a double precision variable.
However, I think you really need to just start reading the basic getting started tutorials.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!