MATLAB Answers

Multiple plots taking different elements of X & Y matrices in a systematic pattern

3 ビュー (過去 30 日間)
Ayan PATSA
Ayan PATSA 2021 年 5 月 23 日
コメント済み: Ayan PATSA 2021 年 5 月 24 日
I have X as a 1x40 matrix with its elements being X1,X2,X3,......,X40. Similarly Y as another 1x40 matrix with elements being Y1,Y2,Y3,....,Y40.
Now I want to have a graph which takes the first four values of X (i.e. X1-4) and first four of Y (i.e. Y1-4) and shows their plot. Then again take next four values for each(i.e. X5-8 & Y5-8) and plot them differently in the same graph and so on.. In this way I want to have 10 different plots in the same graph.
Is there any way to do it (loops maybe) other than just doing it separately for each?

採用された回答

darova
darova 2021 年 5 月 23 日
Try reshape
x = linspace(0,10,40);
y = sin(x);
x1 = reshape(x,[4 10]);
y1 = reshape(y,[4 10]);
plot(x1,y1)
  1 件のコメント
Ayan PATSA
Ayan PATSA 2021 年 5 月 24 日
Yes it works. Thank you

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

その他の回答 (1 件)

Girijashankar Sahoo
Girijashankar Sahoo 2021 年 5 月 23 日
x=[1:1:40];
y=[1:1:40];
l=length(x)/4
n=1
for i=1:l
plot(x(1,n:4*i),y(1,n:4*i))
hold on
n=4*i+1;
end
  1 件のコメント
Ayan PATSA
Ayan PATSA 2021 年 5 月 24 日
This is perfect. Thank you.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by