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에 대해 자세히 알아보기

질문:

2017년 12월 16일

답변:

2017년 12월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by