Arguments satisfy for a range of n when I use stepseq function

8 次查看(过去 30 天)
I receive an error ' arguments must satisfy n1 <= n0 n<= n2' for the below rectangular function.
How can I fix this error?
-----------------------------------------------------------------------------------------------------
% Define variables
n= -40:40;
nlower=n(1);
nupper=n(end);
M1=[10,25,50,101]
M1 = 1×4
10 25 50 101
for m=1:4
M=M1(m);
rec=stepseq(0,nlower,nupper)-stepseq(M,nlower,nupper)
% Calculating DTFT
subplot(3,1,1);
w= (-100:100)*pi/100;
Rec=dtft(rec,n,w);
end
Unrecognized function or variable 'stepseq'.

回答(1 个)

Walter Roberson
Walter Roberson 2023-2-19
nlower is -40, nupper is +40.
M1(3) = 50 is not in the range -40 to +40, so when you call stepseq(50, -40, +40) then you get the error message.
Note that stepseq() is a third-party function, not provided by Mathworks. It appears to have been designed to create a vector of 0 from (integer) nlower to the value of the first parameter, and then 1 from there to (integer) nupper. The behaviour if the first parameter is out of range is not well defined -- should it create a vector of false values from the given value to the lower bound if it is below the lower bound? Should it create a vector of false values from the upper bound to the value if it is greater than the upper bound? The result would be of variable length, which would not be in keeping the the expected uses of stepseq of returning a fixed-length result.
  2 个评论
Gizem Karslioglu
Gizem Karslioglu 2023-2-19
编辑:Walter Roberson 2023-2-19
Yes, I have used below step sequence function. When I change n and w, number of rec is double of n and w. I couldn't be able to match the numbers properly. Do you have any recommendation?
% Define variables
n= -100:100;
nlower=n(1);
nupper=n(end);
M1=[10,25,50,101]
for m=1:4
M=M1(m);
rec=stepseq(0,nlower,nupper)-stepseq(M,nlower,nupper)
% Calculating DTFT
subplot(3,1,1);
w= [-150:150]*pi/100;
Rec=dtft(rec,n,w);
plot(w,Rec, 'LineWidth', 2)
grid on
grid minor
set(gca,'Fontsize', 8);
xlabel(' \omega');
ylabel('X(n)');
--------------------------------------------------------------------------
%Function:
function [xx,nn] = stepseq(n0,n1,n2)
if ((n0 < n1) || (n0 > n2) || (n1 > n2))
error('arguments must satisfy n1 <= n0 <= n2')
end
nn = n1:n2;
%x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))];
xx = (nn-n0) >= 0;
end
And, I see result of the signal like a sinusoidal however I expect to see a rectangular. Do I need to plot for each M value?
Walter Roberson
Walter Roberson 2023-2-19
You do not have hold on so each M value is going to overwrite the previous plots.

请先登录,再进行评论。

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by