フィルターのクリア

create a variable and specify its column

3 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2020 年 6 月 28 日
コメント済み: alpedhuez 2020 年 6 月 29 日
Suppose I have a table
day temperature
1/1/2020 30
I want to create a vaiable 'month" from 'day' and put it next to 'day' like
day month temperature
1/1/2020 1 30
Please advise.
  2 件のコメント
the cyclist
the cyclist 2020 年 6 月 28 日
For you future reference, it is better to actually show what you have via MATLAB syntax (or actually uploading the data). Otherwise, we need to guess about the formats of everything.
Specifically, is day a string, a character array, or a datetime?
alpedhuez
alpedhuez 2020 年 6 月 29 日
'movevar' will allow to choose the location of a variable in a table.

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

採用された回答

the cyclist
the cyclist 2020 年 6 月 28 日
The specifics will depend on what format the variable day is. Here, I assume it is a datetime.
% Create the table
day = datetime('1/1/2020');
temperature = 30;
T = table(day,temperature);
% Derive month from day
T.month = month(day);
% Rearrange the columns
T = T(:,[1 3 2])
You might find this documention page helpful.

その他の回答 (1 件)

Gaganjyoti Baishya
Gaganjyoti Baishya 2020 年 6 月 28 日
Hi
You can get the month from the day string by iterating it till you get the month.
for i=1:size
if day(i)=='/'
if day(i+2)=='/'
month=day(i+1);
else
month=day(i+1) + day(i+2) %char concatenate
end
break;
end
month gives the required value of month. You just need to put it in the column.
  1 件のコメント
alpedhuez
alpedhuez 2020 年 6 月 29 日
Thank you.

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

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by