WHy do I get "ans = 1" in the Command Window?

In running a program I have written using the pdepe function, and sometime during the function call:
soln=pdepe(m,@solnpde,@solnic,@solnbc,r,t,options);
I get a lot of "ans = 1" scrolling in the Command Window. The solution pdepe returns appears to be correct.
What does this mean? How can it be suppressed?
Thanks, Doug

回答 (4 件)

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 7 日

1 投票

Check all of the three functions solnpde, solnic and solnbc. There must be a line somewhere that doesn't have the ; at the end, thus the output is shown in the Command Window.
Run the following line and then run your program. Hope it can help you find where the ans=1 comes from.
echo on all

4 件のコメント

Douglas
Douglas 2011 年 10 月 7 日
Thanks Fangjun,
Unfortunately this has not helped. All lines in solnpde, solnic and solnbc have the ; at the end.
Do you have any further ideas?
Doug
Jan
Jan 2011 年 10 月 7 日
@Douglas: Please search again. One of the called function contains a line with a missing trailing semicolon. You can use the debugger to find this line: set a breakpoint in the code and step through the code line by line until the "ans = 1" appears.
Or let MLint check this for you: Open all called functions in the editor and look for the MLint warnings on the right side.
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 7 日
Yes. You can see from the below example how 'ans = 1' appear. You probably have some debugging line accidentally left in the code. Use break point to narrow down while file and then trace down to the line. You have to follow all the functions that are called.
>> 2-1;
>> 2-1
ans =
1
>> a=1;
>> a=1
a =
1
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 7 日
See updated answer for a possible way to find it out.

サインインしてコメントする。

Walter Roberson
Walter Roberson 2011 年 10 月 7 日

0 投票

Try
dbstop in disp
and then run. When it stops in the debugger, look at the code. There will not be any explicit call to disp() in the situation you are seeing, but disp() is what is called internally.
Though it might be "display" instead of "disp"... I have not had reason to figure out which of the two names is used in which circumstances.

3 件のコメント

Daniel Shub
Daniel Shub 2011 年 10 月 7 日
From the help:
DISPLAY(X) is called for the object X when the semicolon is not used to terminate a statement.
Then in the doc it says taht when overloading display: "A typical implementation of display calls disp to do most of the work ..."
While display is what is being called if there is a missing semicolon. If a hard coded disp or printf is causing the output, then it might be disp that is being called.
Walter Roberson
Walter Roberson 2011 年 10 月 7 日
Thanks for chasing that down!
Daniel Shub
Daniel Shub 2011 年 10 月 7 日
I had thought that a solution to this question would have been to overload display/disp to call dbstack so I was looking at what is being called. It turns out that display is super special and cannot be "overloaded". If you write a function called display.m and put it in your current directory, MATLAB ignores it.

サインインしてコメントする。

Daniel Shub
Daniel Shub 2011 年 10 月 7 日

0 投票

Do you have any eval statements in your code. It is possible that all your "lines" are terminated with a semicolon, but that the eval is not.
x = 1;
eval('x');
compared to
eval('x;');
Jan
Jan 2011 年 10 月 7 日

0 投票

There is also a difference between these two calls:
fprintf(1, '\n'); % Print a line break in the command window
fprintf('1', '\n'); % Print a '1' to the command window
The 2nd ignored the '\n' and is most likely not intented, but a typo.

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

タグ

質問済み:

2011 年 10 月 7 日

コメント済み:

2025 年 2 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by