How to not get an ans from function?

8 ビュー (過去 30 日間)
Jenny Andersen
Jenny Andersen 2019 年 11 月 23 日
コメント済み: Star Strider 2019 年 11 月 23 日
Hi,
I have created a function and it works the way I want it to. However, when I run the function I keep getting an 'ans' and I am not exactly sure why.
In the command window it looks like this:
The following vectors fulfill the demands above:
u2=[0,-1,1]
u3=[0,1,-1]
ans =
0 -1 1

採用された回答

Star Strider
Star Strider 2019 年 11 月 23 日
There are at least two possibilities.
(1) You have omitted a closing semicolon (;) somewhere in the function.
(2) You called the function without an output argument, and did not put a closing semicolon on the function call.
Without seeing your function and your call to it, I cannot speculate as to other reasons.
  2 件のコメント
Jenny Andersen
Jenny Andersen 2019 年 11 月 23 日
編集済み: Jenny Andersen 2019 年 11 月 23 日
Ok, I see. But my function does have an output argument as well as closing semicolon.
function [u2, u3] = Exercise(W);
Star Strider
Star Strider 2019 年 11 月 23 日
Your call to ‘Exercise’ (in your script) apparently does not have a closing semicolon. The function declaration itself does not need a closing semicolon.
For example:
This is correct:
function [u2, u3] = Exercise(W)
and this will not print ‘ans’ to your Command Window because it has an output assignment and a closing semicolon:
W = ...;
[u2, u3] = Exercise(W);
You can then use ‘u2’ and ‘u3’ afterwards in your script.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by