Problem with creating datetime and number array
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
newton zeus
am 2 Mai 2020
Kommentiert: newton zeus
am 2 Mai 2020
Hello!
I'm trying to convert the first column to datetime format, then write the two columns to an array:
19036.055 68.5714
19036.906 70.4225
19037.758 70.4225
19038.633 68.5714
19039.547 65.6455
19040.469 65.0759
19041.367 66.8151
19042.219 70.4225
19043.117 66.8151
May I ask what is wrong with my code?
nDat = size(hrData.VarName1,1);
BPMdata = zeros(nDat,2);
for nCount = 1:nDat
BPMdata(nCount,1) = datetime(hrData.VarName1(1:end), 'ConvertFrom','posixtime');
BPMdata(nCount,2) = hrData.VarName2(1:end);
end
This is the error message: "The following error occurred converting from datetime to double: Undefined function 'double' for input arguments of type 'datetime'. To convert from datetimes to numeric, first subtract off a datetime origin, then convert to numeric using the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions."
Thank you!
Akzeptierte Antwort
Walter Roberson
am 2 Mai 2020
I'm trying to convert the first column to datetime format, then write the two columns to an array:
You cannot do that. Any one array (that is not a structured data type such as a cell array or table) must have the same data type for all of its elements. In order to put both a datetime and a numeric value into the same array, either the datatime must be converted to numeric or else the numeric value must be converted to datetime.
You could use a cell array with two columns, or you could use a table() object. You appear to already be using a table object, so it might make the most sense to use a table.
Or you could convert the datetime into a datenum.. those are numeric.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!