Fix for " The input to DATENUM was not an array of strings."
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ming Au
il 7 Ott 2016
Commentato: Walter Roberson
il 26 Ott 2020
I am attempting to use datenum on my table (one column, first column) of dates to convert it into a separate variable of just a series of numbers
dataset = readtable('equity_dataset_30.csv');
data = dataset(:,2:31);
date = dataset(:,1);
date_num = datenum(date, 'yyyy-mm-dd');
This last line keeps returning the error: " The input to DATENUM was not an array of strings."
Could someone show what I'm missing here?
0 Commenti
Risposta accettata
Steven Lord
il 7 Ott 2016
The variable dataset is a table. When you index into a table with parentheses, the result is also a table. When you index into a table using curly braces, the result is the type of the underlying data. Compare:
x = (1:5).';
y = int8(x.^2);
T = table(x, y);
tableSubarray = T(1:3, 'x');
doubleSubarray = T{1:3, 'x'};
int8Subarray = T{4:5, 'y'};
whos tableSubarray doubleSubarray int8Subarray
You don't want to pass something like tableSubarray into datenum -- you want to pass something like doubleSubarray or int8Subarray (only you want to specify a char array, not a numeric array.)
Once you have the subarray of your table containing character representations of your dates, I recommend that you convert them into a datetime array rather than converting them into serial date numbers using datenum.
2 Commenti
Peter Perkins
il 10 Ott 2016
Steve's right, but perhaps even simpler, if you want to access a single variable, would be
doubleSubarray = T.x(1:3);
int8Subarray = T.y(4:5);
Più risposte (1)
Massimo Zanetti
il 7 Ott 2016
Most probably your variable "date" is not an array of strings.
7 Commenti
NN
il 26 Ott 2020
thank you .It worked.
But i am getting spike like output when i plot datenum and forecasted output.Doesnt look lik wave form .
Kindly advice
Walter Roberson
il 26 Ott 2020
I do not see any obvious problem with the plot. It looks to me like what you would expect for a plot displayed with an unfortunate aspect ratio. Try zooming it.
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!