loop variable picking elements of three different vectors separately
1 view (last 30 days)
Show older comments
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 Comment
Answers (1)
Vishesh
on 27 Oct 2022
- 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 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!