Unable to perform assignment because dot indexing is not supported for variables of this type.

7 views (last 30 days)
RiskFree = readtable("DTB3.csv", 'TreatAsEmpty',{'.','NA'});
RiskFree = rmmissing(RiskFree);
% Extract Data / Select only the period going from 01-10-2015
Data0 = RiskFree{1389:end,2};
date0 = RiskFree{1389:end,1};
% Standardize the date format to match the one of sector indices
datetime.setDefaultFormats('defaultdate','dd-MMM-yyyy');
date0.Format = 'defaultdate';
I get "Unable to perform assignment because dot indexing is not supported for variables of this type."
What should I do?
  4 Comments
Image Analyst
Image Analyst on 30 Mar 2020
AFTER you read this link, attach your CSV file so people can try things. But date0 is not a class or a structure. What does this say:
whos date0
and don't forget to attach the CSV file.
Julien Rivier
Julien Rivier on 1 Apr 2020
I attached here the csv file.
This is what I get when running whos date0:
Name Size Bytes Class Attributes
date0 1115x1 142720 cell
Thanks

Sign in to comment.

Answers (1)

Guillaume
Guillaume on 1 Apr 2020
The error is easily explained. You're expecting readtable to read the first column of your csv as a datetime. You haven't checked that it does and it turns out that it doesn't (because it's not obvious to matlab that it is a date). It reads the column as text so date0 ends up as a cell array.
One way to force matlab to read the column as date:
opts = detectImportOptions('DTB3.csv');
opts = opts.setvaropts('DATE', 'Type', 'datetime', 'InputFormat', 'dd.MM.yy', 'DatetimeFormat', 'dd MMM yyyy');
RiskFree = readtable('DTB3.csv', opts);
Note that the way the date is encoded in your file is ambiguous. If you can, change whatever creates these files so that it encodes the year with 4 digits.

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!