Matlab Command Window Output Source -


possible duplicate:
find location of current m-file in matlab

does knows how find function providing output command window in maltab? i've written code many functions, have output command window can't find function responsible that. !

if output printed own code, can replace fprintf , disp calls own function calls optionally prefix output function name.

here's code:

getfunctionname.m:

function [currentfunctionname, previousfunctionname] = getfunctionname() currentfunctionname = ''; previousfunctionname = ''; mystack = dbstack('-completenames'); if (length(mystack) < 2)     error('function getfunctionname.m cannot called matlab console.'); elseif (length(mystack) == 2)     currentfunctionname = mystack(2).name; else     currentfunctionname = mystack(2).name;     previousfunctionname = mystack(3).name; end return 

myprintf.m:

function myprintf(varargin) global prefixoutputwithfunctionname if (prefixoutputwithfunctionname)     [~, previousfunctionname] = getfunctionname;     fprintf('### %s.m:\n', previousfunctionname); end disp(sprintf(varargin{:})); return 

mydisp.m:

function mydisp(varargin) global prefixoutputwithfunctionname if (prefixoutputwithfunctionname)     [~, previousfunctionname] = getfunctionname;     fprintf('### %s.m:\n', previousfunctionname); end disp(varargin{:}); return 

mainfunction.m:

function mainfunction() global prefixoutputwithfunctionname  % set prefixoutputwithfunctionname false disable prefixing. prefixoutputwithfunctionname = true;  % code goes here...  % example output. myprintf('some text...\n more text...'); return 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -