Assume I have the function:
function name_the_paramlist(varargin)
% Print out varargin exactly how it is called as a string
Basically what
Well, if you type this function call in a command line or run with F9 (so it get saved in the history) you can read the history.m
file and get the last command as a string.
fid = fopen(fullfile(prefdir,'history.m'),'rt');
while ~feof(fid)
lastcmd = fgetl(fid);
end
fclose(fid);
Then get the argument part:
arg_str = regexp(lastcmd, '\w+\((.+)\)','tokens','once');
arg_str = strrep(arg_str{:},'''','''''');
UPDATE:
Another idea. If you call this function from another script or function (m-file) you can use DBSTACK to return the m-file name and the current line number:
SI = dbstack;
filename = SI(end).file;
lineNo = SI(end).line;
Then you can follow similar technique as in the first solution to read that line from the m-file and get argument part.
In opposite to the first solution this won't work if run from command line or editor cell mode.