suppressing the display of ans
이전 댓글 표시
How can I suppress or omit the display of the "ans" when executing my function?
댓글 수: 8
John hebert
2014년 9월 26일
편집: Walter Roberson
2017년 4월 22일
To suppress 'ans' return of function file don't assign an output; find the variable and use disp(variable).
Jack in No. Adams Ma.
Eugene Rivera
2020년 3월 11일
Tried this and it worked. Thanks John
Veeraj Arora
2020년 9월 28일
^
Kenny Perez
2020년 11월 18일
thank you very much
Michele Rocca
2021년 2월 19일
I solved this issue by doing this (but I tried for one output only):
function a=myfunction(b)
%here is yor code
if nargout<1
clear a
end
end
Abhiram V. P. Premakumar
2022년 11월 11일
편집: Abhiram V. P. Premakumar
2022년 11월 11일
vmin=0.9737;
vmax=1.0263;
disp(' vmin vmax')
disp([vmin,vmax])
Kavya
2023년 8월 24일
When you enter a command without a semicolon at the end, MATLAB displays the result.
>> x = 5 + 1
x =
6
Nikhanze
2023년 12월 21일
Enter k = 8-2; including the semicolon at the end. The result won't appear in the command window,but you can see the value of k in workspace browser
채택된 답변
추가 답변 (7개)
Wayne King
2012년 2월 9일
Put a semicolon at the end of the line.
x = randn(8,1);
fft(x);
댓글 수: 4
Pramod Bhat
2012년 2월 9일
Dale is asking how to hide the word 'ans' when there are no arguments. for ex if u just type 2+2 on workplace it will display
ans=
4.
He does not want this 'ans' to be displayed.
Wayne King
2012년 2월 9일
The OP said he wants to suppress the "display" of ans, that's why I told the OP to put a semicolon at the end of the line:
>>2+2;
does what the OP asks as I answered.
George Fega
2017년 4월 22일
You are the best, dude! Thank you vrey much!
Le Yu
2019년 1월 31일
That's exactly what I need!! THx
Matt Tearle
2012년 2월 9일
What Wayne said. But to dig a bit deeper: given that you specifically said "function", I'm guessing you might be confused by the whole local vs global variable thing.
If you have
function y = myfun(x)
y = cos(x.^2);
Then you say
>> z = myfun(pi)
The value of pi is passed into the function where it is assigned to the local variable x; the value of the local variable y is computed and returned to the base workspace according to how the function was called at the command line. In this case, the return value is assigned to the (base) variable z. Because there's no semicolon at the end of that line, the output from that assignment is echoed to the command window. So if you call it as
>> myfun(pi)
MATLAB, as always, assigns the calculated value to ans. Again, there's no semicolon, so you see the result displayed. Note that this display has nothing to do with the line y = cos(x.^2); in the function. If you leave off the semicolon there, you'll see that assignment echoed to the command window -- y = -0.9027 -- and the assignment to ans as well -- ans = -0.9027.
If the function has no return values, nothing will be assigned to ans:
function myfun(x)
plot(x)
>> myfun(1:5)
Allen Bibal
2017년 2월 25일
편집: Allen Bibal
2017년 2월 25일
2 개 추천
A=5;
B=4;
z=A+B;
disp(Z)
Pramod Bhat
2012년 2월 9일
1 개 추천
It is not possible. Where there are no arguments MATLAB automatically makes "ans" a variable and assigns value to it. You cant hide it.
댓글 수: 1
Walter Roberson
2012년 2월 9일
Probably not correct. You can override the display() function, which is what is invoked to output a value when there is no semi-colon after an expression.
Kenneth Cantos
2016년 8월 25일
0 개 추천
is there a code that can hide an output on the command window but the item to be hide will be needed on the succeeding formula.
for example:
i will set A=1+2 B=1+3
Formula:
Z=A+B
Z=9
I want to show only the result of Z.
thanks guys.
댓글 수: 1
Walter Roberson
2016년 8월 25일
Like
Z=A+B;
?
Niklas Berg
2022년 10월 13일
If your output argument is called x for example just type
clear x
in the end of your function. Then x won't show as ans in the command window.
Kavya
2023년 8월 24일
0 개 추천
When you enter a command without a semicolon at the end, MATLAB displays the result.
>> x = 5 + 1
x =
6
Optionally, you can add a semicolon to the end of a command so that the result is not displayed. MATLAB still executes the command, and you can see the variable in the Workspace browser.
>> x = 5 + 1;
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!