hi,
i want to calculate datetime from datenum, i do know for a single cell, how can i do it for the data of 50000 datenum by creating individual column with date and time...
its urgent please reply asap..

 採用された回答

Star Strider
Star Strider 2020 年 9 月 12 日

0 投票

These all work:
dnv = datenum(now) + (0:10).'; % Numeric Array
dt1 = datetime(dnv, 'ConvertFrom','datenum')
dnc = num2cell(dnv); % Cell Array
dt2 = datetime([dnc{:}].', 'ConvertFrom','datenum')
dt3 = datetime(cell2mat(dnc), 'ConvertFrom','datenum')
Choose the one that you like best.

6 件のコメント

komal chauhan
komal chauhan 2020 年 9 月 13 日
hey, when i applied this, it started showing dates and time from today , where in actual it should be fro 4th july 2018...
whats the problem???
i am applying:
t = datetime(7.372457569675926e+05,'ConvertFrom','datenum') for 1st cell and i have 50000 datas ahead...
Star Strider
Star Strider 2020 年 9 月 13 日
I used ‘now’ simply to create a vector to use to test my code, because I did not have a sample of your data.
When I run the line you posted:
t = datetime(7.372457569675926e+05,'ConvertFrom','datenum')
I get:
t =
datetime
04-Jul-2018 18:10:02
It should produce something similar of the rest of your vector as well. Please attach a sample of your data (preferably as a .mat file) if there continue to be problems.
komal chauhan
komal chauhan 2020 年 9 月 13 日
hi there this is my .mat file...
i am willing to produce datetime for all the recorded results..(1:56364) cells of datenum
please go through it ones and tell me where the changes need to be made...
Thank you so much for your prompt reply...
Star Strider
Star Strider 2020 年 9 月 13 日
Try this:
D = load('LAeq_Results.mat');
Result = D.Result;
C = squeeze(struct2cell(Result));
DT = datetime(cell2mat(C(1,:,:)), 'ConvertFrom','datenum');
with:
First_10 = DT(1:10).'
producing:
First_10 =
10×1 datetime array
04-Jul-2018 18:10:02
04-Jul-2018 19:40:02
05-Jul-2018 10:40:02
11-Jul-2018 16:40:04
11-Jul-2018 16:50:04
11-Jul-2018 17:00:04
11-Jul-2018 17:10:04
11-Jul-2018 17:20:04
11-Jul-2018 17:30:04
11-Jul-2018 17:40:04
I transposed it to a column to make it easier to display. (The structure has a unusual format (at least in my experience), so I converted it to a cell and then to a matrix to work with it. Converting it to a table is another option.)
.
Stephen23
Stephen23 2020 年 9 月 14 日
komal chauhan's incorrectly posted "Answer" moved here:
thank you...
i want to know how can i select random 3000 data out of 15000 data from the table...??
TIA
Star Strider
Star Strider 2020 年 9 月 14 日
As always, my pleasure!
‘i want to know how can i select random 3000 data out of 15000 data from the table...??’
Use the randperm function, specifically:
Rows = randperm(15000, 3000);
This will give you the row indices. After that, if ‘T1’ is your table:
T1_Select = T1(Rows,:);
will be the new (3000xN) table.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Dates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by