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

조회 수: 8 (최근 30일)
Gizem Karslioglu
Gizem Karslioglu 2023년 2월 19일
댓글: Walter Roberson 2023년 2월 19일
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