Azzera filtri
Azzera filtri

How do I plot a timeseries graph using this data?

5 visualizzazioni (ultimi 30 giorni)
Leah McGrath
Leah McGrath il 21 Ago 2020
Commentato: Dana il 21 Ago 2020
I am trying to plot a time-series graph relating to my long-frequency stimulation data. However, I am unsure of what I am doing wrong. I am comparing four different variables, with time along the bottom in seconds on the x axis and the fractional change on the y axis.
I have four different variables.
  • LPS_trials_time2
  • LPSold_trials_time2
  • saline_trials_time2
  • salineold_trials_time2
I also have a time variable. When I have tried to plot by creating a vector of y involving the four variables and compare it alongside time, it states that vectors must be the same length.
  2 Commenti
KSSV
KSSV il 21 Ago 2020
When you plot your x, y should be of same size.
Leah McGrath
Leah McGrath il 21 Ago 2020
I understand this, I am just confused as to how! :)

Accedi per commentare.

Risposte (1)

Dana
Dana il 21 Ago 2020
By "creating a vector of y involving the four variables", I'm guessing you actually mean creating a matrix, i.e., by trying to put the four variables together as
y = [LPS_trials_time2, LPSold_trials_time2, saline_trials_time2, salineold_trials_time2];
That will only work if you have the same number of elements in each of those variables (a matrix is rectangular, so each column must have the same number of elements), and it sounds like you don't. So you can't plot in this way.
If you do have different numbers of elements in each variable, you first have to decide how they line up, time-wise. For example, do they all start on the same date (e.g., date 0) but end on different dates? Or end on the same date, but start on different dates? Or are they at different frequencies (e.g., one is monthly data, and another is yearly, so that the second would only have an obersvation on months evenly divisible by 12)?
Once you work that out, you can plot each of the variables separately on the same axis by something like:\
figure
hold on % this is A key step; without it, successive plot commands
% will replace whatever's on the figure, rather than being
% added to it
plot(t1,y1)
.
.
plot(t4,y4)
where yj is data series j, and tj is the vector of dates corresponding to that particular data series.
  2 Commenti
Leah McGrath
Leah McGrath il 21 Ago 2020
Thank you for your response! I did indeed mean matrix, sorry.
I do have the same number of elements for those variables (1x10), which is what is confusing me. I am trying to compare their fractional change across time, so I am wondering whether it is an issue with the time variable.
Dana
Dana il 21 Ago 2020
Ah, I see. It should be straightforward to check whether the time variable also has 10 elements (e.g., using the size() function). If not, then you've found your problem.
FYI, it would be helpful in future if you posted the lines of code that you're running and the exact error message. Makes it much easier for someone to help you diagnose the problem.

Accedi per commentare.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by