Unable to perform assignment because dot indexing is not supported for variables of this type.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Image Analyst
2020년 3월 30일
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.
답변 (1개)
Guillaume
2020년 4월 1일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!