How do I plot a timeseries graph using this data?

4 ビュー (過去 30 日間)
Leah McGrath
Leah McGrath 2020 年 8 月 21 日
コメント済み: Dana 2020 年 8 月 21 日
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 件のコメント
KSSV
KSSV 2020 年 8 月 21 日
When you plot your x, y should be of same size.
Leah McGrath
Leah McGrath 2020 年 8 月 21 日
I understand this, I am just confused as to how! :)

サインインしてコメントする。

回答 (1 件)

Dana
Dana 2020 年 8 月 21 日
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 件のコメント
Leah McGrath
Leah McGrath 2020 年 8 月 21 日
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 2020 年 8 月 21 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by