Plot date on X axis

1 vue (au cours des 30 derniers jours)
wenchong chen
wenchong chen le 14 Fév 2021
Commenté : Walter Roberson le 15 Fév 2021
I am so confused on all other answers. Just trying to make a plot with date in X.
I created close=TSLA(:,5) and date=TSLA(:,1), they worked, then I tried plot(date,close), error. after I check other same question, I tried dn=datenum(date,'mm-dd-yyyy') but It give me error, I am stacked here. I am new to matlab. also how can I plot if the month is not number but like sep, oct?
  2 commentaires
Rik
Rik le 14 Fév 2021
Did you do a basic Matlab tutorial? Onramp should teach you how to deal with tables.
wenchong chen
wenchong chen le 14 Fév 2021
no, I am very new here, just started to watch

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Fév 2021
close = TSLA{:,5};
date = TSLA{:,1};
plot(date, close)
  2 commentaires
wenchong chen
wenchong chen le 14 Fév 2021
amazing, that working, but that is how I did, why my code didn't work but yours work? is that ( ) and {} different?
Walter Roberson
Walter Roberson le 15 Fév 2021
Yes, {} and () indexing is different for MATLAB.
There are two different major kinds of arrays in MATLAB: arrays of uniform objects, and container arrays in which every container might have a different kind of content. Consider for example:
The inside is a uniform array of drinking glasses. The MATLAB way of referring to any one of those glasses is with () brackets -- glasses(1,1) to glasses(3,4) for any one glass.
But now think about the box; close it up. It might be one of a palette-load of boxes the same size. Maybe all the boxes on the palette happen to contain the same kind of glasses; maybe some of them contain plates. You can have an array of boxes, and treat the boxes as individual objects, and when you do that you would still use () indexing -- boxes(1,1,1) to boxes(3,4,2) perhaps for a 3 x 4 x 2 stack of boxes. The () treat the array as uniform. You can take a subset of the boxes, like the left-most "face" of the palette, a 3 x 1 x 2 array of boxes, and you would still use () indexing for that.
But now you need to be able to talk about what is inside one of those containers, and inside the containers are arrays of objects. {} indexing is used to talk about what is inside a container. boxes{1,4,2} perhaps to open the box in row 1, column 4, layer 2. boxes{1,4,2} would refer to the entire contents of the box as an array; you can then use () indexing to refer to the objects within in. So perhaps boxes{1,4,2}(2,3) to refer to the glass in row 2, column 3, inside the box in row 1, column 4, layer 2. And if you open the next box, boxes{2,4,2} for example, it might be the plates, and might be a different sized of array. Maybe a single stack, 1 x 1 x 8.
So, () indexing: don't open any containers, treat the containers themselves as individual objects. {} indexing: open containers, don't expect that what you find there will be the same thing as what you find in a different container in the same array of containers.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Time Series Objects dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by