필터 지우기
필터 지우기

unable to overcome syn_sin error message

조회 수: 1 (최근 30일)
Jacob
Jacob 2023년 9월 12일
답변: Walter Roberson 2023년 9월 12일
I am trying to write following script file in matlab for an assignment
function [xx,tt]=syn_sin(fk, Xk,fs,dur,tstart)
if nargin<5
error('input arguments for the function syn_sin required more')
elseif nargin ==5
tstart = 0;
end
k=length(fk);
if k~=length(Xk)
error('Here fk,Xk should be equal elements');
end
[xx,tt]=one_cos(1,0,0,fs,dur,tstart);
for i=1:1:k
xx=xx+one_cos(fk(i),abs(Xk(i)),angle(Xk(i)),fs,dur,tstart);
end
However I am not able to get this file to do anything but error and I get the following error below
Error using syn_sin
input arguments for the function syn_sin required more
Nothing I try works and I have to use syn_sin so I don't know why there is an error.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 9월 12일
You probably want:
  • if nargin<4 give an error message
  • if nargin == 4 set tstart = 0
Your current code does not allow 6 or more inputs because there are only 5 input positions and the final one is not varargin
Your current code does not allow 0, 1, 2, 3, or 4 inputs because that is < 5 .
So when you reach the elseif you know that nargin must be 5 exactly. But then you test for 5 (which is certain to be the case if you reach there) and if it is true (which it always will be if you reach the elseif in this code) then you set tstart = 0 -- overwriting any tstart the user might have passed in.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by