Code doesn't display outputs correctly

Below shows the code that I'm working on.
function [PF1, PF2]=CPF(xi,eta,xk,yk,nkx,nky,L)
A=L^2;
B=2*L*(-nky*(xk-xi)+nkx*(yk-eta));
E=(xk-xi)^2+(yk-eta)^2;
D=sqrt(abs(4*A*E-(B^2)));
BA=B/A;
EA=E/A;
if (D<0.0000000001)
PF1=0.5*L*log(L)+(1+0.5*BA)*(log(abs(1+0.5*BA)))-0.5*BA*log(abs(0.5*BA))-1;
PF2=0;
else
PF1=0.25*L*(2*log(L)-1)-0.5*BA*log(abs(EA))+(1+0.5*BA)*log(abs(1+BA+EA))+(D/A)*(atan((2*A+B)/D));
PF2=L*(nkx*(xk-xi)+nky*(yk-eta))/D*(atan((2*A+B)/D)-atan(B/D));
sprintf('\n\t%f %f\n\n',PF1,PF2);
end
Upon calling the function in Command Window, the output given is:
>>CPF(xi,eta,xk,yk,nkx,nky,L)
PF1 is 11.248000. PF2 is 27.763502
ans =
11.2480
I like to check if there's a way to either remove the "ans = 11.2480" line or have the ans show the 2nd value which is 27.76...
Any help will be appreciated. Thanks!

1 commentaire

Priyank Upadhyaya
Priyank Upadhyaya le 1 Oct 2012
When you call CPF(xi,eta,xk,yk,nkx,nky,L); use a semicolon in the end that will remove the ans = 11.24.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 1 Oct 2012
As explained in the Getting Started chapters of the documentation, the output of "ans = ..." disappears, when you set a semicolon after the calling command:
[PF1, PF2] = CPF(xi,eta,xk,yk,nkx,nky,L);
To display the 2nd output use simply:
PF2
or:
disp(PF2)

Plus de réponses (0)

Catégories

En savoir plus sur Functions dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by