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?

 采纳的回答

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.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by