MATLAB: Keeps getting error while using num2str

datadatedatenumdateserrorformathelpMATLABnum2strxlsread

if true
[Data,~,~] = xlsread('CRSP_daily','WRDS');
Data(:,1) = datenum(num2str(Data(:,1),'yyyymmdd'));
/define start and end date
start_date_monthly = datestr('1962-01-01');
end_date_monthly = datestr('2016-12-30');
Erase = (Data(:,1) < datenum(start_date_monthly) |...
Data(:,1) > datenum(end_date_monthly));
Data(Erase,:) = [];
end
The first column of "Data" consists of dates in this format: "19271214" .. But I still seems to get an error saying the 'yyyymmdd' is an invalid format.
Any suggestions?

Best Answer

yyyymmdd would be a date format, not an option for converting numbers to strings.
Unfortunately you did not describe the content of Data(:,1) at the beginning, so it is difficult to make recommendations.
If you have R2014b or later I suggest you consider switching to using datetime() objects; in particular I suspect that https://www.mathworks.com/help/matlab/ref/datetime.html#mw_3234162f-7406-4c76-88b6-54e33b23095a 'convertfrom', 'excel' might be of interest to you.