How to adjust plots with several subplots with different loops?

4 ビュー (過去 30 日間)
Amelie
Amelie 2023 年 6 月 3 日
コメント済み: Amelie 2023 年 6 月 4 日
Dear all,
I a have problem in adjusting the loop in the subplots and hope, that someone can help me with it.
What I would like to plot is:
However, I would like to automate and shorten it by loops with:
Unfortunately, the loop for the subplot does not match the loop for the y matrix, i.e., in subplot (1,3,1) I get the 3 times y(:,1) for the y axis instead of y(:,1), y(:,2), y(:,3). Is there a way to fix this or do I have to plot it individually ?
Thanks a lot for your help!
Regards,
Anna
  2 件のコメント
Catalytic
Catalytic 2023 年 6 月 3 日
編集済み: Catalytic 2023 年 6 月 3 日
Your code cannot be copy&pasted since it is not posted as text. Therefore, it is unlikely anyone will try to modify it.
Amelie
Amelie 2023 年 6 月 4 日
Thanks for the advice! I haven't thought about that, but you are absolutely right.

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

採用された回答

VBBV
VBBV 2023 年 6 月 3 日
編集済み: VBBV 2023 年 6 月 3 日
You can modify the for loop something like this as shown below
x = rand(1,10);
z = rand(1,10);
w = rand(1,10);
k = 0;
figure
for ii = 1:3
y = rand(10,3);
subplot(1,3,ii)
hold on
plot(x,y(:,k+ii),'linewidth',4,'Color','cyan')
plot(z,y(:,k+ii+1),'linewidth',2,'Color','red')
plot(w,y(:,k+ii+2),'linewidth',1.5,'Color','blue')
k = k - 1;
legend('show')
end

その他の回答 (1 件)

Catalytic
Catalytic 2023 年 6 月 3 日
編集済み: Catalytic 2023 年 6 月 3 日
ord={x,z,w};
for i=1:3
subplot(1,3,i);
h=plot(ord{i},y,'LineWidth',4);
[h.Color]=deal('cyan','red','blue');
end

カテゴリ

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