use the same function for multiple cells in a row.

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..

 Respuesta aceptada

Star Strider
Star Strider el 12 de Sept. de 2020
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 comentarios

komal chauhan
komal chauhan el 13 de Sept. de 2020
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...
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 el 13 de Sept. de 2020
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...
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 el 14 de Sept. de 2020
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
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 12 de Sept. de 2020

Comentada:

el 14 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by