Function 'subsindex' is not defined for values of class 'datetime'.

6 Ansichten (letzte 30 Tage)
alpedhuez
alpedhuez am 12 Jun. 2018
Kommentiert: Walter Roberson am 13 Jun. 2018
I have a simplest possible csv file but still cannot plot(test.X,test.Y) with the above message. Please advise.
  6 Kommentare
Walter Roberson
Walter Roberson am 12 Jun. 2018
If you do wish to use the dates as the X axis, then which MATLAB release are you using?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Walter Roberson
Walter Roberson am 12 Jun. 2018
With sufficiently new MATLAB:
T = readtable('test.csv');
plot(T.X, T.Y)
  5 Kommentare
Matt Dickson
Matt Dickson am 13 Jun. 2018
It's not because people may confuse it with 1609, as you said, but because the plot as you showed would simply show the year as "9", not "09". Hence, if you want the date with a normal year format with the year at the bottom and not part of each tick mark, you do need to add 2000 to each year.
Walter Roberson
Walter Roberson am 13 Jun. 2018
Ah, I had never noticed the XRuler.SecondaryLabel for datetime plots before. And the appropriate code all appears to be built-in, so I can't poke through it :(

Melden Sie sich an, um zu kommentieren.


OCDER
OCDER am 12 Jun. 2018
FID = fopen('test.csv');
Data = textscan(FID, '%D%f', 'Delimiter', ',', 'Headerlines', 1);
fclose(FID);
Data{1}.Year = Data{1}.Year + 2000; %Assuming you want 2009, etc.
plot(Data{1}, Data{2})

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by