MATLAB: Periodic function with n cycles

periodic

Hi, I need to create a periodic function and plot it.
F(x)=sqrt(3) + *Sin(t -2*pi/3) --> 0<t<pi/3
F(x)=Sin(t) --> pi/3 <t<2*pi/3
repeat the signal 0<t<3*pi with the period 2*pi/3 Then plot(t,Fx)
------
At the moment I use the following code
>> t1=0:.01:pi/3;
>> t2=pi/3:.01:2*pi/3;
A=sqrt(3) + sin(t1*2*pi- 2*pi/3);
B=sin(t2);
plot(t1,A,t2,B)
This method is produce the answer a one cycle. However it is quite difficult to repeat the pattern for multiple times.
Can any one n please suggest way of doing this

Best Answer

t = 0:pi/100:6*pi;
t1 = rem(t,2*pi/3);
l = t1 < pi/3 ;
F = @(t,l)sqrt(3)*l + sin((2*pi*l + ~l).*t -2*pi/3*l);
out = F(t1,l);
plot(t,out)
ADD
t = 2*pi*(0:.0005:1).';
t1 = rem(t,2*pi/3);
l1 = t1 < pi/3;
l0 = ~l1;
y = zeros(numel(t),2);
y(l1,1) = sqrt(3) + sin(t1(l1) - 2*pi/3);
y(l0,1) = sin(t1(l0));
y(l1,2) = sin(t1(l1) - 2*pi/3);
y(l0,2) = sin(t1(l0)) - sqrt(3);
yy = sin([t,bsxfun(@plus,t,[1, -1]*2*pi/3)]);
plot(t,[y,yy]);