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

7 visualizaciones (últimos 30 días)
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 comentarios
Image Analyst
Image Analyst el 30 de Mzo. de 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 el 1 de Abr. de 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

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
Guillaume el 1 de Abr. de 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.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by