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?

 採用された回答

John D'Errico
John D'Errico 2017 年 12 月 16 日
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 ExchangeStartup 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