How can I plot a block function?

 Accepted Answer

Hi Eliane,
Here is the code that does it
t = -1:0.01:1; % Set the limits of span
x = zeros(length(t),1); % Initialize an array with zeros
t1 = t>=-0.5 & t<0.5; % Find the indices between -0.5 and 0.5
x(t1) = cos(3*pi*t(t1)); % Assign those indices with cosine function
plot(t,x) % Plot the figure
Hope this helps.
Regards,
Sriram

2 Comments

Thank you, this was indeed were I was looking for!
Do accept the answer if helpful

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!