Unable to perform assignment because dot indexing is not supported for variables of this type.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 30 Mär. 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.
Antworten (1)
Guillaume
am 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!