MATLAB Answers


how to generate square wave in matlab

Asked by md
on 16 Jun 2014
Latest activity Commented on by Image Analyst
on 15 Jun 2017
I intend to generate a square wave with respect to time by following characteristic:
I want to generate square-wave force demand of 1 KN at 10 Hz. That means amplitude will be between 0 to 1000 and time will be between 0 to 1 (sec) with .1 interval.
Please someone help me.


Sign in to comment.

3 Answers

Answer by Image Analyst
on 16 Jun 2014
 Accepted Answer

Make one period, then use repmat() to replicate as many times as you want.


Just Put a saturation block with lower limit zero. It will give only Positive value.
I don't know what that means. What is a "saturation block"? Is that Simulink? The poster said "in matlab" but if your function is for Simulink, then perhaps your post will help Simulink users.

Sign in to comment.

Answer by Rashmil Dahanayake on 16 Jun 2014



Sign in to comment.

Answer by udhaya ram mohan on 18 Oct 2016

i need to generate the square wave with positive cycle only please send me a code for it

  1 Comment

Rashmil Dahanayake's Answer already only generates positive values.

Sign in to comment.