Converting Dates in the Cell Array into Serial Numbers

Hi, I am trying to convert the dates that are currently in a cell array into serial numbers so that they could be used in a plot. The source is a .csv file. datenum() doesn't work with cell arrays and cellfun(@datenum,serialDates) gives me an array with all identical serial numbers. I don't know what else I could do. I included below a sample of data and a part of the script. I would strongly appreciate any help. Please note: "Date Time" is a single column in a .csv file.
Date Time Vibration Temperature Current
7/25/2011-8:40:34 0.1314 114.3 49.5359
Script:
userCell = textscan(fid,'%s%s%s%s','Delimiter',',');
[dates,vibration,temperature,current]=userCell{1,1:4};
dates=dates(2:end,1);
Thank you!

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 29 日

1 投票

It seems to work for me. "all identical serial numbers" may be just a visual thing. They are actually different. You can use datestr() to check.
test.txt
Date Time Vibration Temperature Current
7/25/2011-8:40:34 0.1314 114.3 49.5359
7/25/2011-8:40:35 0.1314 114.3 49.5359
fid=fopen('test.txt','rt');
userCell =textscan(fid,'%s%f%f%f','HeaderLines',2);
dates=userCell{1};
a=datenum(dates)
b=datestr(a)
fclose(fid);
a =
1.0e+005 *
7.3471
7.3471
b =
25-Jul-2011 08:40:34
25-Jul-2011 08:40:35

1 件のコメント

Jan
Jan 2011 年 7 月 29 日
@Artem: As you see in this example, DATENUM does work with cell strings:
datenum({'7/25/2011-8:40:34', '7/25/2011-8:40:34'})

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

その他の回答 (1 件)

Artem
Artem 2011 年 8 月 1 日

0 投票

Thank you for your help!

カテゴリ

ヘルプ センター および 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