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 Comment

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

Sign in to comment.

 Accepted Answer

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)

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Tags

Asked:

CWK
on 1 Oct 2012

Community Treasure Hunt

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

Start Hunting!