Question
I want to plot a square wave centered around the Y-axis.
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 12, 2026
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)
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →