Skip to content

Commit

Permalink
* Null assignment (x(...)=[]) with a single index is now possible w…
Browse files Browse the repository at this point in the history
…ith function `(`

* Added functions to simplify indexing rows of columns of 2D arrays: `Y)`, `Z)` for reference indexing; `Y(`, `Z(` for assignment indexing. The latter allow null assignment with a single index.

* Added function `conv2(...,'valid')` (`Z+`)

* `cumsum`, `cumprod` now allow char input

* Renamed functions "linearize array", "comma-separated list", `gallery`

* Octave compatibility for `diff` and `mod` with char input

* Octave compatibility with `repelem` (thanks, @beaker!)

* Fixed incorrect <strong>...</strong> tags in Octave
  • Loading branch information
lmendo committed Jan 28, 2016
1 parent d48b071 commit 79fcafe
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 29 deletions.
7 changes: 7 additions & 0 deletions compatibility/diff_comp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function y = diff(varargin)
% Allows first input to be char
if ischar(varargin{1})
varargin{1} = double(varargin{1});
end
y = builtin('diff', varargin{:});
end
10 changes: 10 additions & 0 deletions compatibility/mod_comp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function y = mod(varargin)
% Allows inputs to be char
if ischar(varargin{1})
varargin{1} = double(varargin{1});
end
if ischar(varargin{2})
varargin{2} = double(varargin{2});
end
y = builtin('mod', varargin{:});
end
19 changes: 19 additions & 0 deletions compatibility/repelem_comp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function y = repelem(varargin)
% Implements Matlab's `repelem` in Octave
if nargin==2 && isvector(varargin{1}) && isvector(varargin{2}) && numel(varargin{2})>1
ind = repelems(1:numel(varargin{1}), [1:numel(varargin{1}); varargin{2}(:).']);
y = varargin{1}(ind);
elseif nargin==2 && isvector(varargin{1}) && isvector(varargin{2}) && numel(varargin{2})==1
ind = repelems(1:numel(varargin{1}), [1:numel(varargin{1}); repmat(varargin{2},1,numel(varargin{1}))]);
y = varargin{1}(ind);
elseif nargin>2
ind = cell(1,nargin-1);
for k = 2:nargin
r = varargin{k};
ind{k-1} = ceil(1/r:1/r:size(varargin{1},k-1));
end
y = varargin{1}(ind{:});
else
error('Inputs not supported')
end
end
Binary file modified doc/MATL_spec.pdf
Binary file not shown.
Binary file modified funDef.mat
Binary file not shown.
103 changes: 81 additions & 22 deletions funDef.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion genHelp.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
commFormatted = {F.comment};
descrFormatted = {F.description};
descrFormatted = regexprep(descrFormatted, '\\matlab(.)(.*?)(\1)', '<strong>$2</strong>');
descrFormatted = regexprep(descrFormatted, '\\matl\+(.*?)\+', '<strong>$1</strong>'); %***make delimiter arbitrary her too
descrFormatted = regexprep(descrFormatted, '\\matl\+(.*?)\+', '<strong>$1</strong>'); %***make delimiter arbitrary here too
descrFormatted = regexprep(descrFormatted, '\\comp{(.*?)}', '<strong>$1</strong>');
descrFormatted = regexprep(descrFormatted, '\\sa', 'See also');
descrFormatted = regexprep(descrFormatted, '\$(.*?)\$', '$1');
Expand Down
Binary file modified help.mat
Binary file not shown.
18 changes: 13 additions & 5 deletions matl.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ function matl(varargin)
verNum = version(indMainName).Version; % version number as a string
verNum = str2double(regexp(verNum, '\.', 'split')); % version number as a vector

useTags = isMatlab && (verNum(1)>7 || (verNum(1)==7 && verNum(2)>=13));
if useTags
strongBegin = '<strong>';
strongEnd = '</strong>';
else
strongBegin = '';
strongEnd = '';
end

if numel(varargin)==0
options = 'r';
inputNeeded = true;
Expand All @@ -46,15 +55,15 @@ function matl(varargin)
s = varargin{2};
inputNeeded = false;
elseif numel(varargin)==2 && varargin{1}(1)~='-'
error('MATL:main', 'MATL error while processing options: two input strings have identified, but the first string does not begin with <strong>-</strong>')
error('MATL:main', 'MATL error while processing options: two input strings have identified, but the first string does not begin with %s-%s', strongBegin, strongEnd)
else
error('MATL:main', 'MATL error while processing options: the number of inputs cannot exceed 2')
end
if any(options=='r') && any(options=='d')
error('MATL:main', 'MATL error while processing options: incompatible options <strong>r</strong> and <strong>d</strong>')
error('MATL:main', 'MATL error while processing options: incompatible options %sr%s and %sd%s', strongBegin, strongEnd, strongBegin, strongEnd)
end
if any(options=='l') && any(options=='e')
error('MATL:main', 'MATL error while processing options: incompatible options <strong>l</strong> and <strong>e</strong>')
error('MATL:main', 'MATL error while processing options: incompatible options %sl%s and %se%s', strongBegin, strongEnd, strongBegin, strongEnd)
end
if ~ismember(options,'plecsrdh')
options = [options 'r'];
Expand All @@ -65,7 +74,7 @@ function matl(varargin)
verbose = false;
end
if any(options=='h') && any(ismember(options, ['plecrdf' '0':'9' 'A':'Z']))
error('MATL:main', 'MATL error while processing options: <strong>h</strong> is not compatible with specified options')
error('MATL:main', 'MATL error while processing options: %sh%s is not compatible with specified options', strongBegin, strongEnd)
end
if any(options=='o')
online = true; % saffe mode, for online compiler
Expand Down Expand Up @@ -207,7 +216,6 @@ function matl(varargin)
end

% Call help, if required, and quit
useTags = isMatlab && (verNum(1)>7 || (verNum(1)==7 && verNum(2)>=13));
if any(options=='h')
if nargin>1
matl_help(H, s, verbose, useTags)
Expand Down
3 changes: 2 additions & 1 deletion matl_compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@
if ~isMatlab
appendLines('', 0)
appendLines('% Define subfunctions', 0)
fnames = {'num2str' 'im2col' 'spiral' 'unique' 'union' 'intersect' 'setdiff' 'setxor' 'ismember' 'triu' 'tril' 'randsample' 'nchoosek' 'vpa' 'sum' 'mean'};
fnames = {'num2str' 'im2col' 'spiral' 'unique' 'union' 'intersect' 'setdiff' 'setxor' 'ismember' ...
'triu' 'tril' 'randsample' 'nchoosek' 'vpa' 'sum' 'mean' 'diff' 'mod' 'repelem'};
for n = 1:numel(fnames)
fname = fnames{n};
if any(~cellfun(@isempty,strfind(C,fname))) % This may give false positives, but that's not a problem
Expand Down

0 comments on commit 79fcafe

Please sign in to comment.