how to define a new variable in a table

I have a table
date temperature
1/1/2020 10
1/2/2020 20
1/3/2020 30
I want to define a variable 'even' that takes a value of 1 if the day is the even number and 0 if the day is the odd number. That is,
date temperature even
1/1/2020 10 0
1/2/2020 20 1
1/3/2020 30 0
Please advise.

 採用された回答

madhan ravi
madhan ravi 2020 年 6 月 17 日

0 投票

TablE.even = [0; 1; 0]

6 件のコメント

alpedhuez
alpedhuez 2020 年 6 月 17 日
編集済み: alpedhuez 2020 年 6 月 17 日
The above one is an example. I want to understand how to write a if else to define a varaible in a table like, assuming test is the table name,
if day(test.date) == even
test.even == 1
else
test.even ==0
end
madhan ravi
madhan ravi 2020 年 6 月 17 日
DO NOT USE table as a variable name.
TablE.even = day(TablE.date) == evem
alpedhuez
alpedhuez 2020 年 6 月 17 日
Thank you. I have corrected errors. Still, I want to understand, in a more general example, how to define a new variable in a table using if else. Thank you.
madhan ravi
madhan ravi 2020 年 6 月 17 日
TablE.even = false(size(TablE.date));
for k = 1:numel(TablE.date)
TablE.even(k) = day(TablE.date(k)) == evem;
end
alpedhuez
alpedhuez 2020 年 6 月 17 日
Thank you. What is the difference between size(TablE.date) and numel(TablE.date)?
madhan ravi
madhan ravi 2020 年 6 月 17 日
doc size
doc numel

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

製品

タグ

質問済み:

2020 年 6 月 17 日

コメント済み:

2020 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by