Extract numeric year from string

Need to complete the implementation of the date2Year function, which extracts the numeric 4-digit year value from a date string, such as might be returned by the Matlab date() function.
Input variable: str (string containing date to be tested)
Output variable:Year (The numeric year-part of the date)
Script is to begin with: function year = date2Year( str )
Also suggested functions that can be used is str2num() or str2double()

답변 (1개)

Thorsten
Thorsten 2015년 3월 27일

2 개 추천

datestr = date;
year = str2num(datestr(end-3:end));

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2015년 3월 27일

답변:

2015년 3월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by