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 で Multirate Signal Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!