MATLAB: How can I get the square wave in matlab MATLABwave when the y-axis = 1, -5 < t < -1 when the y-axis = -1, -1 < t < 3 t = linspace(-5, 3, samples+1);f = square(t);figure(1)plot(t, f) thank you in advance Best Answer Try this:samples = 100;t = linspace(-5, 3, samples+1);f = 1*((t >= -5) & (t <= -1)) + (-1)*((t > -1) & (t <= 3)); figure(1)plot(t, f)axis([-5.5 3.5 -1.1 1.1])EDIT â Changed âtâ and axis limits to reflect edited limits (about 04:00 UCT 11 Mar 2018) in original Question. Related SolutionsMATLAB: How to generate this signal Try this:t = linspace(0, 40, 250);f = 1*((t >= 10) & (t <= 20)) + (-1)*((t > 20) & (t <= 30)); figure(1)plot(t, f)axis([xlim -1.1 1.1]) MATLAB: How to plot a square wave centered around the Y-axis in MATLAB The following code sample plots a square wave with an amplitude of 1 between -0.5 to +0.5 and 0 else where.t = -0.5:0.01:0.5;y = square(2*pi*.25*t,100);plot(t,y)tl = -1:0.01:-0.5;yl = square(0*pi*.25*tl,0);tr = 0.5:0.01:1;yr = square(0*pi*.25*tl,0);tg = [tl t tr];yg = [yl y yr];plot(tg,yg) Related QuestionHow to plot below function fPlot exponential graph of the given equationPlotting unit step function
Best Answer