Skip to content

Commit 5ab061c

Browse files
committed
Zv with two inputs
`Zv` with two inputs: symmetrize array along specified dimension
1 parent 02f00e0 commit 5ab061c

File tree

9 files changed

+11
-7
lines changed

9 files changed

+11
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MATL
22
A programming language based on MATLAB/Octave and suitable for code golfing
33

4-
The compiler works in MATLAB R2015b or newer. Probably in older versions too, except for some specific functions. It is also compatible with Octave 4.0.0. The compiler tries to ensure consistent behaviour in both platforms. In addition, you can use it at [Try it online!](http://matl.tryitonline.net) and at [MATL Online](https://matl.suever.net/).
4+
The compiler works in MATLAB R2015b or newer. Probably in older versions too, except for some specific functions. It is also compatible with Octave 4.0.0. The compiler tries to ensure consistent behaviour in both platforms. In addition, you can use it at [Try it online!](https://tio.run/#matl) and at [MATL Online](https://matl.suever.net/).
55

66
Installation: unpack the compressed file to a folder, and make that folder part of MATLAB's or Octave's search path.
77

funDef.mat

401 Bytes
Binary file not shown.

funDef.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,10 +1648,14 @@ Yv 1 2 1 1 3 1 [false true false] true true true true if isnumeric(in{1}) eigen
16481648
% The above is needed to include 0 as whitespace
16491649
out{1} = strtrim(in{:});
16501650
end
1651-
Zv 1 1 1 1 1 1 true true true true if isnumeric(in{1}) remove trailing blanks (i) For numeric input \matlab+n+: symmetric range. For nonnegative \matlab+n+ it rounds down and then gives \matlab+[1:n n-1:-1:1]+; for negative \matlab+n+ it removes sign, rounds down and gives \matlab+[n:-1:1 2:n]+. (ii) For string or cell array input: \matlab+deblank+
1651+
Zv 1 2 1 2 1 1 1 true true true true if (numel(in)==1) && (numel(in{1})==1) && isnumeric(in{1}) symmetric range / symmetric array / remove trailing blanks (i) For one numeric input \matlab+n+: symmetric range. For nonnegative \matlab+n+ it rounds down and then gives \matlab+[1:n n-1:-1:1]+; for negative \matlab+n+ it removes sign, rounds down and gives \matlab+[n:-1:1 2:n]+. (ii) For two inputs: applies symmetric range indexing to the first input along the dimension given by the second input, without repeating the last entry. If the second input is negative the last entry is repeated. (iii) For one string or cell array input: \matlab+deblank+
16521652
if in{1}>=0, in{1} = floor(in{1}); out{1} = [1:in{1} in{1}-1:-1:1]; else, in{1} = floor(-in{1}); out{1} = [in{1}:-1:1 2:in{1}]; end
1653-
else
1653+
elseif numel(in)==1
16541654
out{1} = deblank(in{:});
1655+
else
1656+
removelast = in{2}>0; dim = abs(in{2});
1657+
inds = repmat({':'}, 1, ndims(in{1})); inds{dim} = [1:size(in{1}, dim) size(in{1}, dim)-removelast:-1:1];
1658+
out{1} = in{1}(inds{:}); clear inds dim removelast
16551659
end
16561660
w 0 inf 2 0 0 0 false true false true if ~isempty(in), in([1 end]) = in([end 1]); STACK(end+nin) = in; end swap elements in stack swap elements in stack
16571661
Xw

help.mat

106 Bytes
Binary file not shown.

spec/MATL_spec.pdf

421 Bytes
Binary file not shown.

spec/funDefTable/funDefTable.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
\matl{Zu} & 1--2 (1) & 1 & \matlab+strjust+ \\
242242
\matl{v} & 0-- ($^\ddagger$ / 2) & 1 & \matlab+vertcat+. If inputs are matrices with non-matching sizes they are linearized \\
243243
\matl{Yv} & 1--2 (1) & 1--3 (1 / 2nd) & (i) If input is numeric: with $1$ or $2$ outputs: \matlab+eig+. With $3$ outputs: \matlab+svd+. (ii) If input is a string or cell array of strings: \matlab+strtrim+. For string or char array input, char $0$ also counts as whitespace \\
244-
\matl{Zv} & 1 & 1 & (i) For numeric input \matlab+n+: symmetric range. For nonnegative \matlab+n+ it rounds down and then gives \matlab+[1:n n-1:-1:1]+; for negative \matlab+n+ it removes sign, rounds down and gives \matlab+[n:-1:1 2:n]+. (ii) For string or cell array input: \matlab+deblank+ \\
244+
\matl{Zv} & 1--2 (1 / 2) & 1 & (i) For one numeric input \matlab+n+: symmetric range. For nonnegative \matlab+n+ it rounds down and then gives \matlab+[1:n n-1:-1:1]+; for negative \matlab+n+ it removes sign, rounds down and gives \matlab+[n:-1:1 2:n]+. (ii) For two inputs: applies symmetric range indexing to the first input along the dimension given by the second input, without repeating the last entry. If the second input is negative the last entry is repeated. (iii) For one string or cell array input: \matlab+deblank+ \\
245245
\matl{w} & 0-- (2) & 0 & swap elements in stack \\
246246
\matl{x} & 0-- (1) & 0 & delete from stack \\
247247
\matl{Xx} & 0--1 (0 / 1) & 0 & \matlab+clc+. With $1$ input \matlab+x+: \matlab+pause(x/10)+ and then \matlab+clc+. Inputs \matl{F} and \matl{T} are interpreted as \matl{2.5} and \matl{10} respectively \\

spec/functionTable/MATL.xlsx

-5 Bytes
Binary file not shown.

spec/functionTable/function_table.eps

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
1 Byte
Binary file not shown.

0 commit comments

Comments
 (0)