How do I plot a timeseries graph using this data?
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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 个评论
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 Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!