MATLAB: How to level shift a sine wave mathematically

60 hzlevel shiftMATLABMATLAB and Simulink Student Suitesine wave

Hello MatLab users,
Im currently working on a small program that gives me a certain number of values of a 60 Hz sine wave signal but unfortunately I was only able to create a sine wave that has positive and negative values, but what I really want is to get only positive values so I would need my sine wave to be level shifted up (for example 0 to 3). Is there any way to do this? I want to do this mathematically only. Help is appreciated, thank you all. I leave my code below and picture of plot of the sine wave.
f = 60;
fs = 1e4; % samples per second
t=0:1/fs:0.017; % 1/fs is seconds per sample
x = sin(2*3.14*f*t);
plot(t,x)
x(:)

Best Answer

Sure, it's just a linear scaling from the [-1,1] interval to [minV,maxV]
x = sin(2*3.14*f*t);
M=[maxV-minV]/2; % slope --> [maxV-minV]/[1-(-1)]
B=1+minV; % intercept
z=M*(x+B); % scale
for your min,max of [0,3] then
M=(3-0)/2;
B=1+0;