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

조회 수: 6 (최근 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
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.
Julien Rivier
Julien Rivier 2020년 4월 1일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
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.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by