Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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);

Risposte (1)

Stalin Samuel
Stalin Samuel il 3 Mar 2016
  • 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

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by