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 次查看(过去 30 天)
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 个评论
Nicole Peltier
Nicole Peltier 2020-5-30
编辑:Nicole Peltier 2020-5-30
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!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by