loop variable picking elements of three different vectors separately
2 次查看(过去 30 天)
显示 更早的评论
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 个)
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;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!