Error: Too many output arguments

I have written a code for my final year project . I called a crn(). I get a error that too many arguments. but when I run the function code alone, I get the output with single argument.
function crn(tow)
Q =20;
Pi=[0.3,0.4,0.2,0.5,0.4];
Pa=10;
%tow=0.5
Pdbar=15;
Y=4;
fs=10000;
yi=[1,3,5,2,3];
y1=[1,2,5,8,7];
y2=10;
yj=[2,3,4,5,2];
N=5;
z=sum(Pi(2:N).*yi(2:N));
S=(Pa*y2)/(1+z);
alpha=sqrt((2*Y)+1)*Q^-1*Pdbar;
a=sum(Pi(2:N).*y1(2:N));
yj=yj(3:N);
yj=[yj 0];
b=sum(Pi(2:N).*yj);
bet=sum(log2((1+(sum(Pi(2:N).*yi(2:N))/(1+b)))))-(a/(1+a));
A = ((1-(Q*(alpha+(sqrt(tow*fs)*Y))))+((1-tow)*((Y*sqrt(fs))/(2*sqrt(2*3.14)))*tow^(-0.5)*exp(-(alpha+(sqrt(tow*fs)*Y))^2)/2));
B = (log2(1+((tow*S)/(1-tow)))+((1-tow)*(1-(Q*(alpha+(sqrt(tow*fs)*Y))))*(S/(((bet+1)*(1-tow))+(S*tow))*(1-tow))));
dR_tow=((A*B*10^(-7))/3);
%disp(dR_tow);
end
T=1;
tow_min=0;
tow_max=T;
while (tow_max-tow_min)>0.02
tow_bar=(tow_max+tow_min)/2;
a=crn(tow_bar);
b=crn(tow_min);
if a==b
tow_min=tow_bar;
else
tow_max=tow_bar;
end
end
tow0=tow_bar;
disp("tow0="+tow);

1 comentario

Stephen23
Stephen23 el 25 de Feb. de 2020
Editada: Stephen23 el 25 de Feb. de 2020
"...but when I run the function code alone, I get the output with single argument."
Nope.
At the end of your function you use disp to display something, but the function does not return any output arguments:

Iniciar sesión para comentar.

 Respuesta aceptada

Subhadeep Koley
Subhadeep Koley el 25 de Feb. de 2020
Hi, this is because you function crn is not returning anything. If you want to return dR_tow then use the code below.
function dR_tow = crn(tow)
Q =20;
Pi=[0.3,0.4,0.2,0.5,0.4];
Pa=10;
%tow=0.5
Pdbar=15;
Y=4;
fs=10000;
yi=[1,3,5,2,3];
y1=[1,2,5,8,7];
y2=10;
yj=[2,3,4,5,2];
N=5;
z=sum(Pi(2:N).*yi(2:N));
S=(Pa*y2)/(1+z);
alpha=sqrt((2*Y)+1)*Q^-1*Pdbar;
a=sum(Pi(2:N).*y1(2:N));
yj=yj(3:N);
yj=[yj 0];
b=sum(Pi(2:N).*yj);
bet=sum(log2((1+(sum(Pi(2:N).*yi(2:N))/(1+b)))))-(a/(1+a));
A = ((1-(Q*(alpha+(sqrt(tow*fs)*Y))))+((1-tow)*((Y*sqrt(fs))/(2*sqrt(2*3.14)))*tow^(-0.5)*exp(-(alpha+(sqrt(tow*fs)*Y))^2)/2));
B = (log2(1+((tow*S)/(1-tow)))+((1-tow)*(1-(Q*(alpha+(sqrt(tow*fs)*Y))))*(S/(((bet+1)*(1-tow))+(S*tow))*(1-tow))));
dR_tow=((A*B*10^(-7))/3);
end
Hope this helps!

Más respuestas (1)

Andy
Andy el 25 de Feb. de 2020

1 voto

Assuming that the information you want to return is dR_tow, change the first line of the function to
function [dR_tow] = crn(tow)

Etiquetas

Preguntada:

el 25 de Feb. de 2020

Editada:

el 25 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by