Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Question about plotting time series graph in Matlab

1 回表示 (過去 30 日間)
Niraj Prasad Koirala
Niraj Prasad Koirala 2020 年 7 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi!
I need to plot pictures like the ones attached to this question. I started with Matlab's subplotting commands. But, I am not being able to find the correct answer. I am becoming mad over this for about a week. I would be glad if someone could help me.
  2 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 5 日
Sure, we'll help you. How can we help? I mean there is the plot() function but I'm sure you've already learned about that and tried it, so how else can we help you? I guess you just clicked past the instructions that were there when you posted the questions, so now you should read this link before fixing your post which will enable us to answer.
Niraj Prasad Koirala
Niraj Prasad Koirala 2020 年 7 月 5 日
Hi! I used the following codes to make the quarterly subplots as shown above:
ea = muja(:,1); %muja is file with data
state= muja(:,2);
t = datetime(1966,4,1):calquarters(1):datetime(2020,1,1)
subplot1 = subplot(3,3,1,'Parent',figure);
hold(subplot1,'on');
plot(t,ea,'Parent',subplot1,'Color',[1 0 0])
I got the following notification saying my code is wrong. Could you help me in this case?
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.

回答 (2 件)

Image Analyst
Image Analyst 2020 年 7 月 5 日
Doesn't this look kind of like your image?
t1 = datetime(1971,1,1,8,0,0);
t2 = datetime(2017,1,1,8,0,0);
t = t1 + calmonths(1:46*12)
numPoints = length(t)
y_t = movmean(20 * rand(1, numPoints) - 10, 51);
plot(t, y_t, 'b-', 'LineWidth', 2);
grid on;
xlabel('Date', 'FontSize', fontSize);
ylabel('y_t', 'FontSize', fontSize, 'Interpreter', 'none');
datetick('x', 'mm/dd/yyyy');
ax = gca;
ax.XTickLabelRotation = 90;
  3 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 6 日
編集済み: Image Analyst 2020 年 7 月 6 日
You keep forgetting to attach muja in a .mat file, which means you ignored my advice to read this link.
Too bad. I'll check back later. Also when you post code, highlight the code and click the Code icon so that people can copy it to the clipboard with one click.
In the meantime, this throws no error:
numQuarters = 54;
muja = rand(numQuarters * 4, 2);
ea = muja(:,1);
state= muja(:,2);
t1 = datetime(1966,4,1);
t2 = datetime(2020,1,1);
t = t1 + calquarters(1:54*4)
numPoints = length(t)
% subplot1 = subplot(3,3,1,'Parent',figure);
% hold(subplot1,'on');
whos t, whos ea
plot(t,ea,'b-','linewidth',2);
grid on;
xlabel('Date', 'FontSize', fontSize);
ylabel('ea', 'FontSize', fontSize, 'Interpreter', 'none');
xlim([t1, t2]);
% xticks(t1 : caldays(30) : t2);
datetick('x', 'mm/dd/yyyy');
ax = gca;
ax.XTickLabelRotation = 90;
Niraj Prasad Koirala
Niraj Prasad Koirala 2020 年 7 月 6 日
I am sorry for not attaching the file. Hereby I am attaching the data file. Thanks for your time and help.

Image Analyst
Image Analyst 2020 年 7 月 5 日
Try
plot(subplot1, t, ea, 'r-', 'LineWidth', 2)
grid on;

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by