How do I stop a function from displaying output matrix without using semicolon in command window?
이전 댓글 표시
Here is one of my functions for color histogram equalization:
function [ newimg ] = oldhist( img );
Red = img(:,:,1);
Green = img(:,:,2);
Blue = img(:,:,3);
R = histeq(Red);
G = histeq(Green);
B = histeq(Blue);
newimg= cat(3,R,G,B);
imshow (newimg);
end
If I use it without a semicolon in the command window it will display the newimg matrix. How do I store newimg matrix without displaying the matrix and without using a semicolon in the command window?
댓글 수: 2
Shashank Prasanna
2013년 3월 12일
Why don't you want to use the semicolon? It exists so that you can suppress command line output.
James
2013년 3월 13일
채택된 답변
추가 답변 (1개)
Walter Roberson
2013년 3월 12일
When you call a function that returns a value, the value will be displayed unless the context specifically instructs otherwise (such as with a semi-colon), or unless the context uses the returned value in a calculation in a way that does not display the evaluated value. For example,
if oldhist( img )
end
will use the value output by oldhist() to test for the "if" and will not display the value. Note this particular multi-line form does not use a semi-colon.
It is not possible in a MATLAB routine to find out the name of an output variable.
You could recode as
function oldhist(img, newimgvar )
....
assignin('caller', newimgvar, newimg);
where newimgvar is a string indicating the name of the variable to assign into. For example,
oldhist( eye(5), 'MyResult' )
This is not recommended and will fail if the calling workspace is a static workspace (that is, there is an "end" statement matching its "function" statement.)
If you were hoping for something like a command
displayoutputs off
then there is no such command in MATLAB.
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!