フィルターのクリア

Output argument "t" (and maybe others) not assigned during call to "Sum_Cosinefunction".

1 回表示 (過去 30 日間)
Mehtab Khan
Mehtab Khan 2016 年 3 月 3 日
回答済み: Stalin Samuel 2016 年 3 月 3 日
Hi there,
So I'm working on a function that gives the output for a sum of cosines. But when I try to call the function, I get the error Output argument "t" (and maybe others) not assigned during call to "Sum_Cosinefunction". But I've looked over it quite a few times, but I seem to be missing something. Any thoughts? function [t,X] = Sum_Cosine(N,A,f,phi,B,Start,End,fs)
if (N < 0 ) disp('The number of sinusoids must be positive'); end
if ~all(isreal(A)) ~all(A>0) error('Amplitude must be real and postive elements'); end if ~all(isreal(B)) error('B must be real and postive elements'); end
if ~all(isreal(f)) error('f must be real and postive elements'); end
if ~all(isreal(phi)) error('Phi must be real and postive elements'); end
if (isreal(Start) == 0) disp('Starting and Ending time signals must be real'); end if(End < Start) disp('End time must be bigger than start time'); if (fs < (2*f)) disp('Sampling frequency must be greater than double the amount of frequency of the sinusoid'); end
t = linspace(Start,End,fs);
X = 0;
for i=1:N X = X + A(i)*cos(2*pi*f(i)*t + phi(i)) + B(i); end
end
this is my function call: Sum_Cosinefunction(1,5,10,3.14159,2,0,10,20);

回答 (1 件)

Stalin Samuel
Stalin Samuel 2016 年 3 月 3 日
  • In your code the output arguments are assigned within the if condition
  • There is a possibility for your input data may not satisfies the if condition
  • In such situation there is no arguments returned from the function
  • You can avoid this error by defining the state of [t,X] using a else

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by