How to extract year, month, day from character vectors?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Paul Barrette
am 11 Aug. 2022
Kommentiert: Paul Barrette
am 14 Aug. 2022
I have a character vector matrix (I think that's what it's called - it was obtained with cell2mat command applied to a *.csv file) which shows this when I open it (one column):
var =
'1970/01/01'
'1970/01/02'
'1970/01/03'
'1970/01/04'
'1970/01/05'
'1970/01/06'
I would like to produce a numerical matrix X with as many rows but three columns (year, month, day, respectively). I've explored numerous options, to no avail. Any suggestions?
0 Kommentare
Akzeptierte Antwort
Kevin Holly
am 11 Aug. 2022
Bearbeitet: Kevin Holly
am 11 Aug. 2022
var =['1970/01/01'
'1970/01/02'
'1970/01/03'
'1970/01/04'
'1970/01/05'
'1970/01/06']
% I want to make you aware of Datetime arrays
datetime(var,'InputFormat','yyyy/MM/dd')
% Here is how you can convert your data into a numerical matrix containing Year, Day, and Month columns
m = [];
for ii = 1:size(var,1)
m = [m;split(var(ii,:),"/")'];
end
X = str2double(m)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!