"Nezbytným krokem k tomu, abyste od života získali věci, po kterých toužíte, je rozhodnout se, co vlastně chcete."
Stačí vybrat řádek s definicí funkce a spustit níže uvedený kód (ideální udělat si z něj zkratku). Automaticky se připraví šablona na dopsání nápovědy k funkci (vypíší se parametry, popis...):
% matlab help generator - select line with function definition.
% e.g.: function [times, data, var_names, info] = Import(file_path)
author = 'Moje Jmeno (muj@mail.cz)';
editor = matlab.desktop.editor.getActive;
sel = editor.SelectedText;
% parse function
if (strfind(sel,'function')~=1)
error('No function selected.')
else
io1 = strfind(sel,'[');
io2 = strfind(sel,']');
ii1 = strfind(sel,'(');
ii2 = strfind(sel,')');
% parse parameters
outputs = sel(io1+1:io2-1);
outputs = strsplit(outputs,' ');
inputs = sel(ii1+1:ii2-1);
inputs = strrep(inputs,' ','');
inputs = strsplit(inputs, ',');
% create text help
str = sprintf('\n%% %s',sel);
str = sprintf('%s\n%% Function .\n',str);
str = sprintf('%s%%\n%% INPUT\n', str);
for param=inputs
str = sprintf('%s%% %s [] ... \n', str, char(param));
end
str = sprintf('%s%%\n%% OUTPUT\n', str);
for param=outputs
str = sprintf('%s%% %s [] ... \n', str, char(param));
end
str = sprintf('%s%%\n', str);
str = sprintf('%s%% Author: %s\n', str, author);
str = sprintf('%s%% Version: 1.0, %s\n', str, datestr(now,'yyyymmdd'));
str = sprintf('%s%% Changelog: \n%% 1.0 - first implementation\n%%\n', str);
end
editor.insertTextAtPositionInLine(str,editor.Selection(3),editor.Selection(4));
Kód na Mathworku: http://www.mathworks.com/matlabcentral/fileexchange/47843-matlab-help-generator.
.