フィルターのクリア

How to use if statements and for loop to plot the following series?

1 回表示 (過去 30 日間)
Armando MAROZZI
Armando MAROZZI 2020 年 9 月 16 日
コメント済み: Armando MAROZZI 2020 年 9 月 16 日
I am trying to plot the following series in a subplot (6X2). The idea is to have the first column in blue, while the second in red. Besides, I would like to have a legend only in the first graph for each column that explains the meaning of the colours. I tried the following solution but it doesn't work.
VAR.tot = rand(30, 12)
x = (1:size(VAR.tot,1)).'; % Create ‘x’ To Plot Correctly
k = size(VAR.tot,2)
t = [1,3,5,7,9,11]
d = [2,4,6,8,10,12]
for j = 1:k
subplot(6, 2, j);
if (j == t)
plot(VAR.tot(:,j), 'LineWidth',1,'Color', [0.25,0.3,0.8]);
hold on
legend('External Instrument','Location','northwest','Orientation','horizontal')
end
if (j == d)
plot(VAR.tot(:,j), 'LineWidth',1,'Color', [0.6,0.1,0.2]);
hold on
legend('Cholesky','Location','northwest','Orientation','horizontal')
end
yline(0, '-')
end
What I would like to get is similar to the figure attached.
Can anyone help me sort this out?
Thanks a lot!

採用された回答

Alan Stevens
Alan Stevens 2020 年 9 月 16 日
Try replacing
if (j == t)
with
if (mod(j,2)==1)
and
if (j == d)
with
if (mod(j,2)==0)

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by