Is there anyway I can reduce this program to a few lines?
1 view (last 30 days)
Show older comments
Hello,
I would like to reduce this program to 3 lines only or more but not explicit, Any ideas?
x1=-3*pi:0.1:-2*pi;
y1=-cos(x1);
x2=-2*pi:0.1:-pi;
y2=cos(x2);
x3=-pi:0.1:0;
y3=-cos(x3);
x4=0:0.1:pi;
y4=cos(x4);
x5=pi:0.1:2*pi;
y5=-cos(x5);
x6=2*pi:0.1:3*pi;
y6=cos(x6);
plot(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6)
0 Comments
Accepted Answer
Matt J
on 12 Jul 2013
Edited: Matt J
on 12 Jul 2013
x={-3*pi:0.1:-2*pi,
-2*pi:0.1:-pi,
-pi:0.1:0,
0:0.1:pi,
pi:0.1:2*pi,
2*pi:0.1:3*pi}.';
p=[x;cellfun(@(c,n)(-1)^n*cos(c),x,num2cell(1:6),'uni',0)];
plot(p{:})
More Answers (0)
See Also
Categories
Find more on Database Toolbox 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!