フィルターのクリア

Splitting date in a table into different columns

9 ビュー (過去 30 日間)
Maja Zdulska
Maja Zdulska 2020 年 10 月 1 日
編集済み: Stefanie Schwarz 2022 年 5 月 31 日
Hi all,
I'm using the 2019b version of Matlab and I'm currently handling a large dataset in a .csv format, which looks like this:
Date Latitude Longitude Period
01/01/1980 23.9 57.3 2.32
01/01/1980 23.9 57.4 2.37
01/01/1980 24 57.3 2.54
01/01/1980 24 57.4 2.77
01/02/1980 23.9 57.3 2.18
01/02/1980 23.9 57.4 2.45
01/02/1980 24 57.3 2.98
01/02/1980 24 57.4 2.66
I've loaded it using readtable, which works just fine:
T=readtable(MyFile);
date=T(:,1);
I need to split the date into separate columns containing the day, month and year respectively, as later I'm planning to do group averaging of the data (i.e. calculate mean values of Period for different months, years and locations). I've tried:
a=datetime(date,'InputFormat','dd/MM/yyyy');
but I get the error message:
Error using datetime (line 659)
Input data must be a numeric array, a string array, a cell array containing character vectors, or a char matrix.
I'm not sure how to resolve it. Any help on this matter would be much appreciated!
Maja
  1 件のコメント
Stephen23
Stephen23 2020 年 10 月 1 日
You used the wrong kind of brackets. Instead of parentheses (which returns a table):
date=T(:,1);
you need to use curly braces (which returns whatever data type that column has):
date=T{:,1};

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 1 日
編集済み: Ameer Hamza 2020 年 10 月 1 日
  1 件のコメント
Maja Zdulska
Maja Zdulska 2020 年 10 月 1 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by