Create a matrix with columns of both datetime and double format

40 vues (au cours des 30 derniers jours)
David E.S.
David E.S. le 2 Mai 2021
Commenté : Steven Lord le 2 Mai 2021
I want to create a matrix with these vectors:
a = [21-Mar-2021 07:44
21-Mar-2021 17:35
22-Mar-2021 07:48
22-Mar-2021 17:46
23-Mar-2021 07:49
23-Mar-2021 17:48];
b = [21
23
24
26
27
29];
When I try the following sentence, MATLAB gives me an error:
c=[a,b];
Error using datetime/horzcat (line 1335)
All inputs must be datetimes or date/time character vectors or date/time strings.
I don't know how to merge both columns in a single matrix. Can you help me?

Réponse acceptée

Mario Malic
Mario Malic le 2 Mai 2021
Hi,
Use a cell array or a table to do so.
% Using cell array
{datetime('today'), 5}
ans = 1×2 cell array
{[02-May-2021]} {[5]}
% Using table
dt = datetime('now');
num = 5;
table(dt, num)
ans = 1×2 table
dt num ____________________ ___ 02-May-2021 07:20:58 5
  1 commentaire
Steven Lord
Steven Lord le 2 Mai 2021
A table array would work, but a timetable array has some functionality for working with the date and time data above and beyond what you can do with a table.
dt = datetime('now');
num = 5;
tt = timetable(dt, num)
tt = timetable
dt num ____________________ ___ 02-May-2021 15:00:13 5

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by