I have extracted 'time' from excel sheet but got in different format.

2 ビュー (過去 30 日間)
Bishow Shrestha
Bishow Shrestha 2017 年 10 月 7 日
編集済み: per isakson 2017 年 10 月 8 日
my excel time file is in format h:m:s.
0:00:00
0:15:00
0:30:00
0:45:00
1:00:00
1:15:00
1:30:00
1:45:00
2:00:00
2:15:00
2:30:00
I extracted using code:
data = xlsread('winddata','C10:C2980'); % for the month of Jan
Time=data(:,2);
But I got time as 0
0.0104166666666667
0.0208333333333333
0.0312500000000000
0.0416666666666667
0.0520833333333333
0.0625000000000000
0.0729166666666667
0.0833333333333333
0.0937500000000000
0.104166666666667
I do not understand what is this? How can I get time in correct format in matlab as well or hourly. How can we do increment on such excel file in matlab.

回答 (2 件)

per isakson
per isakson 2017 年 10 月 8 日
編集済み: per isakson 2017 年 10 月 8 日
You are right, it's confusing and it's because Excel stores its serial date number internally and shows it on a format chosen by the user. The internal value is shown when the user chose "No specific format". xlsread reads the internal value regardless of what is displayed.
The string 00:15:00 in the cell does not tell whether the underlying value is
  • a character string, which is displayed with the format General or
  • a serial date number, which is displayed with the format Time
Remains the question of how to convert Excel date and time to Matlab. I have long stopped using Excel and forgotten how to make this conversion.
Maybe the new function readtable fixes it automagically.
Guess that the numbers you see are in the unit "day" and make a test
>> 0.0104166666666667 * (24*60)
ans =
15.0000
>> datestr( 0.0104166666666667, 'HH:MM:SS' )
ans =
00:15:00
Indeed they are. Multiply by 24 to get hours or by (24*60) to get minutes.
However, it becomes more tricky when it comes to dates.
This has been ask several times, e.g
@Kian Azami points at datetime, which was "Introduced in R2014b". Thus, the short answer regarding dates is
>> t = datetime( 0.0104166666666667,'ConvertFrom','excel')
t =
1899-12-31 00:15:00

Kian Azami
Kian Azami 2017 年 10 月 8 日
Maybe you can change them to dates and separate the time as follow:
data = xlsread('winddata','C10:C2980'); % for the month of Jan
Time=data(:,2);
dates = char(datetime(Time,'ConvertFrom','datenum'))
YourTimes = dates(:,end-7:end)
Now you have strings which contain the time. You can change them also to Date type if it is necessary.

カテゴリ

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