What is wrong with my code.It's not producing correct figure.The axis should run from -1 to 1,but it's not!
1 view (last 30 days)
Show older comments
Problem 24. Write a function called make_square_waves that takes two
positive integers as input arguments (it does not have to check the format of
the input) and returns a two-dimensional array. If it is called like this
A = make_square_waves(M,N), then A is an N-by-N array of products of
square waves whose amplitude is 1 and whose period is N/M . The result can
be achieved by modifying the function make_waves, which is described in
the previous problem. The modification involves the use of the built-in function
sign. Here is an example:
>> surf(make_square_waves(2,50));axis square
which produces Figure .
function A=make_square_waves(M,N)
A=zeros(N,N);
for ii=1:N
for jj=1:N
A(ii,jj)=sign(M*2*pi*ii/N)*sign(M*2*pi*jj/N);
end
end
end
1 Comment
Nicole Peltier
on 30 May 2020
Edited: Nicole Peltier
on 30 May 2020
Square waves are periodic, so you need to incorporate sine. Below is the equation for a square wave with period T:
squarewave(t) = sign(sin((2*pi*t)/T);
To get your 2D output A, you need to multiply two 1D square waves together.
Give it another shot, and let us know if you need more help!
Answers (0)
See Also
Categories
Find more on Logical 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!