loop variable picking elements of three different vectors separately

1 回表示 (過去 30 日間)
Dharma Khatiwada
Dharma Khatiwada 2022 年 10 月 18 日
回答済み: Vishesh 2022 年 10 月 27 日
Hi,
I am trying to make a loop with loop variable picking elements of three vectors separately. I am trying to keep the result in the same figure with the axis parameters same. I am sharing the code below. How do we generate three plots all in the same figure? Your suggestion will be highly appreciated.
Thanks
Dharma
syms x t
n_weeks = 30;
c1(x) = 1;
vec_1 = reshape((0:n_weeks-1)*7+[1;4],1,[]);%Monday & Thursday
vec_2 = reshape((0:n_weeks-1)*7+[1;3;5],1,[]);%Monday, Wednesday, Friday
vec_3 = zeros(1,60,'uint32');% This vector is simply zero for all days.
for j=[vec_1, vec_2, vec_3] % Here I am trying tell j to pick elements of each vectors separately so that there will be...
% three plots in the same graph with same axis parameter.
c1(x) = c1(x)+15*(x-j);
end
  1 件のコメント
dpb
dpb 2022 年 10 月 18 日
" How do we generate three plots all in the same figure? "
See hold on

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

回答 (1 件)

Vishesh
Vishesh 2022 年 10 月 27 日
  • I am not clear why are you combining "vec_1" , "vec_2" and "vec_3" in "for" loop.
For the given scenario you may try following approach:
  • Calculate the data of each of the three plots and store it seperately.
  • Suppose data stored in "x1", "x2" and "x3";
  • Now you can plot all of these three data in single figure using following approach:
plot(x1,y1);
hold on;
plot(x2,y2);
hold on;
plot(x3,y3);
hold off;

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by