How datetime and integer or float value can co-habitate in an array?

I am trying to save both a float or integer value together with a datetime value in an array. Anyway of making both these values cohabitate in an array?
d= 5.5
e = 05-Feb-2015 18:15:59
f= [d e]
Of course this is an error. But I am trying to map integers values to a datetime value. How i can do this. Should i change the datetime to a string?

2 Commenti

The datetime "e" is a string already. So you have actually:
e = '05-Feb-2015 18:15:59'
with the quotes.
Keep in mind that datetime is a newer object class, and members of that class print out without quotes.

Accedi per commentare.

 Risposta accettata

Use a cell array, as Azzi said, or use a table object.
x = 12345;
t = datetime('today');
A = table(x, t)
For a slightly larger table with some random data for today and the next 9 days:
x = randi(100, 10, 1);
t = datetime('today')+days((0:9).');
t.Format = 'dd-MMM-yyyy'; % Adjust the formatting of the dates to display only day, month, and year
A = table(x, t)

Più risposte (1)

Use cell array
d= 5.5
e = '05-Feb-2015 18:15:59'
f= {d e}
or
d= 5.5
e =datenum( '05-Feb-2015 18:15:59')
f=[d e]
or use struct array
d= 5.5
e ='05-Feb-2015 18:15:59'
f.date=d
f.value=e

9 Commenti

@ Azzi Abdelmalek See this example, where array is a datetime array
array=[05-Feb-2015 18:14:23 05-Feb-2015 18:14:27 05-Feb-2015 18:14:31]
d=5.5
e=array(1)
I was meaning
f=[d e]
I want the output to be like
f= 5.5 05-Feb-2015 18:14:23
Have you read my answer? you can't write e=05-Feb-2015 18:15:59, it's
e ='05-Feb-2015 18:15:59'
Also, I said you can use cell arrays
array={'05-Feb-2015 18:14:23' '05-Feb-2015 18:14:27' '05-Feb-2015 18:14:31'}
d=5.5
e=array(1)
f={d e}
My result is
f= [5.5000] {1x1 cell}
I want to datetime to be displayed.
My second query is that my inital datetime array is very long (about 3000 in length)..how do i convert it automatically between commas?
Azzi probably meant
e = array{1}
rather than
e = array(1)
before the
f = {d e}
It still does not work. What i am expecting is
05-Feb-2015 18:16:03 5
05-Feb-2015 18:17:43 3
05-Feb-2015 18:19:55 1
The datetime value is side by side to an integer value and it should all be displayed at one time. The datetime value i am extracting it from a timestamp values of arrays that is very large.
t = datetime('now','TimeZone','local','Format','d-MMM-y HH:mm:ss Z');
{t 3; t 5}
I do not understand this sentence:
My second query is that my inital datetime array is very long
(about 3000 in length)..how do i convert it automatically between commas?
Sorry for the confusion. What i meant is that i have a very long stream of datetime array. I wanted to display it in a column or table fashion whereby each datetime value corresponds to an integer!

Accedi per commentare.

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by