0
votes

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 11 hours ago.

(Private feedback for you)

From reading in this Excel file into MATLAB:

[frates, fdlable] = xlsread('C:\Users\Nancy\Documents\Research\Data\USTreasury\USTreasuryDataset\FredTreasuryRatesMon','A8:X818')

I get a cell array rates fdlable1 811 by 12 of Excel dates, format m/d/yyyy that I want convert to serial date numbers through datenum.

Must I convert fdlable1 'm/d/yyyy' to a string variable first before using datenum?

Here the assignment fails because there are empty cells in fdlable1:

date_num = cellfun(@datenum, fdlable1, 'UniformOutput', false);

Warning: Usage of DATENUM with empty date character vectors or empty strings is not supported. Results may change in future versions.

fdlable1 =fdlable(:,1:2:23);

811 x 12 from 811 x 23
fdlable: '7/1/1954' '' '7/1/2001' '' '1/1/1934' '' '12/1/1958' '8/1/1954' '' '8/1/2001' '' '2/1/1934' '' '1/1/1959' '9/1/1954' '' '9/1/2001' '' '3/1/1934' '' '2/1/1959' '10/1/1954' '' '10/1/2001' '' '4/1/1934' '' '3/1/1959' '11/1/1954' '' '11/1/2001' '' '5/1/1934' '' '4/1/1959' '12/1/1954' '' '12/1/2001' '' '6/1/1934' '' '5/1/1959' '1/1/1955' '' '1/1/2002' '' '7/1/1934' '' '6/1/1959' '2/1/1955' '' '2/1/2002' '' '8/1/1934' '' '7/1/1959' '3/1/1955' '' '3/1/2002' '' '9/1/1934' '' '8/1/1959' '4/1/1955' '' '4/1/2002' '' '10/1/1934' '' '9/1/1959' '5/1/1955' '' '5/1/2002' '' '11/1/1934' '' '10/1/1959' '6/1/1955' '' '6/1/2002' '' '12/1/1934' '' '11/1/1959' '7/1/1955' '' '7/1/2002' '' '1/1/1935' '' '12/1/1959' '8/1/1955' '' '8/1/2002' '' '2/1/1935' '' '1/1/1960'

fdlable1: '7/1/1954' '7/1/2001' '1/1/1934' '12/1/1958' '7/1/1959' '4/1/1953' '8/1/1954' '8/1/2001' '2/1/1934' '1/1/1959' '8/1/1959' '5/1/1953' '9/1/1954' '9/1/2001' '3/1/1934' '2/1/1959' '9/1/1959' '6/1/1953' '10/1/1954' '10/1/2001' '4/1/1934' '3/1/1959' '10/1/1959' '7/1/1953' '11/1/1954' '11/1/2001' '5/1/1934' '4/1/1959' '11/1/1959' '8/1/1953' '12/1/1954' '12/1/2001' '6/1/1934' '5/1/1959' '12/1/1959' '9/1/1953' '1/1/1955' '1/1/2002' '7/1/1934' '6/1/1959' '1/1/1960' '10/1/1953' '2/1/1955' '2/1/2002' '8/1/1934' '7/1/1959' '2/1/1960' '11/1/1953' '3/1/1955' '3/1/2002' '9/1/1934' '8/1/1959' '3/1/1960' '12/1/1953' '4/1/1955' '4/1/2002' '10/1/1934' '9/1/1959' '4/1/1960' '1/1/1954'

How to get a matrix of serial date numbers?

The corresponding variable rates is:

rates = frates(:,1:2:23); 811 x 12

0.800000000000000   3.61000000000000    0.720000000000000   3.01000000000000
1.22000000000000    3.48000000000000    0.620000000000000   3.09000000000000
1.07000000000000    2.63000000000000    0.240000000000000   3.13000000000000
0.850000000000000   2.24000000000000    0.150000000000000   3.13000000000000
0.830000000000000   1.96000000000000    0.160000000000000   3.27000000000000
1.28000000000000    1.69000000000000    0.150000000000000   3.33000000000000
1.39000000000000    1.65000000000000    0.150000000000000   3.52000000000000
1.29000000000000    1.70000000000000    0.190000000000000   3.82000000000000
1.35000000000000    1.75000000000000    0.210000000000000   3.87000000000000
1.43000000000000    1.69000000000000    0.270000000000000   4.70000000000000
1

1 Answers

0
votes

datenum can not process empty data cells. On a smaller data set this works:

date_num = cellfun(@datenum, fdlable1(1:231,:), 'UniformOutput', false);