フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by