please help "Output argument ‹variable› (and maybe others) not assigned during call to ‹function›". I have attached the required files.

here is the function which is showing error %
function [fr,f_i,f_l,f_a]=find_freqs (H,F)
k=1;
u=1;
f_i=zeros(length(H),1);
for i = 1+u:length(H)-u
if H(i+u)<H(i)
if H(i-u)<H(i)
fr(k)=F(i);
f_i(i)=max(H);
f_l(k)=i;
f_a(k)=H(i);
k=k+1;
end
end
end

 Accepted Answer

Ths usual reason for that error is that the if conditions are not satisfied, so in this instance the output arguments are never assigned. The easiest way to correct that is to always assign something to them, then overwrite that value (here NaN) if the conditions are met.
The Code:
function [fr,f_i,f_l,f_a]=find_freqs (H,F)
k=1;
u=1;
f_i=zeros(length(H),1);
for i = 1+u:length(H)-u
fr(k)=NaN;
f_i(i)=NaN;
f_l(k)=NaN;
f_a(k)=NaN;
if H(i+u)<H(i)
if H(i-u)<H(i)
fr(k)=F(i);
f_i(i)=max(H);
f_l(k)=i;
f_a(k)=H(i);
k=k+1;
end
end
end
Note I did not test the revised code, but it should work.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!