diff --git a/README.md b/README.md index ee999d7..f134ff9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # MATL A programming language based on MATLAB/Octave and suitable for code golf. -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.io). +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/). Installation: unpack the compressed file to a folder, and make that folder part of MATLAB's or Octave's search path. diff --git a/compatibility/bwselect_comp.m b/compatibility/bwselect_comp.m new file mode 100644 index 0000000..6046d58 --- /dev/null +++ b/compatibility/bwselect_comp.m @@ -0,0 +1,15 @@ +function BW2 = bwselect_comp(BW1, C, R, N) +% bwselect in some versions of Octave's Image Package (for example 2.12.0) gives different results +% from those in Matlab. This fixes that. The approach used here is: find the connected components +% and select those that contain any of the input pixels +CC = bwconncomp(BW1, N); +PixelIdxList = CC.PixelIdxList; +clear CC +lin_ind = sub2ind(size(BW1), R(:), C(:)); +BW2 = false(size(BW1)); +for c = 1:numel(PixelIdxList) + if any(ismember(lin_ind, PixelIdxList{c})) + BW2(PixelIdxList{c}) = true; + end +end +end diff --git a/funDef.mat b/funDef.mat index d690854..8b74080 100644 Binary files a/funDef.mat and b/funDef.mat differ diff --git a/funDef.txt b/funDef.txt index 3adbd63..4ebb280 100644 --- a/funDef.txt +++ b/funDef.txt @@ -898,7 +898,7 @@ YI 3 4 3 4 1 1 1 true true true true str = {'distinct' 'sliding'}; rearrange ma if isscalar(in{3}), in{3}(2) = numel(in{1})/in{3}; end if prod(in{3})~=numel(in{1}), in{3} = round(in{3}*sqrt(numel(in{1})/prod(in{3}))); end out{1} = col2im(in{:}); -ZI 1 inf 2 3 1 inf 1 true true true true switch in{end} image processing functions Depending on numeric last input, calls an image processing function with the remaining inputs. $0$: \matlab+imfill+. If first input is logical or numerical it is converted to char. $1$: \matlab+bwlabeln+. $2$: \matlab+imdilate+. This function allows second input to be number $4$, $5$, $8$ or $9$, which is interpreted as the corresponding neighbourhood mask. $3$: \matlab+imerode+. This function allows second input to be number $4$, $5$, $8$ or $9$, which is interpreted as the corresponding neighbourhood mask. $4$: \matlab+bweuler+. $5$: \matlab+bwselect+ with $4$ inputs. +ZI 1 inf 2 3 1 inf 1 true true true true switch in{end} image processing functions Depending on numeric last input, calls an image processing function with the remaining inputs. $0$: \matlab+imfill+. If first input is logical or numerical it is converted to char. $1$: \matlab+bwlabeln+. $2$: \matlab+imdilate+. This function allows second input to be number $4$, $5$, $8$ or $9$, which is interpreted as the corresponding neighbourhood mask. $3$: \matlab+imerode+. This function allows second input to be number $4$, $5$, $8$ or $9$, which is interpreted as the corresponding neighbourhood mask. $4$: \matlab+bweuler+. $5$: \matlab+bwselect+ with $4$ inputs and $1$ output. case 0 if islogical(in{1}) || ischar(in{1}), in{1} = double(in{1}); end [out{:}] = imfill(in{1:end-1}); diff --git a/help.mat b/help.mat index 2ea5200..71ab0cd 100644 Binary files a/help.mat and b/help.mat differ diff --git a/matl_compile.m b/matl_compile.m index 52481a2..d1ab5ae 100644 --- a/matl_compile.m +++ b/matl_compile.m @@ -368,7 +368,7 @@ 'triu' 'tril' 'randsample' 'nchoosek' 'vpa' 'sum' 'mean' 'prod' 'diff' 'mod' 'repelem' 'dec2bin' 'dec2base' ... 'hypergeom' 'disp' 'str2func' 'logical' 'circshift' 'pdist2' 'strsplit' 'max' 'min' 'strncmp' 'round'... 'datestr' 'regexp' 'regexprep' 'imshow' 'mat2str' 'blkdiag' 'strcat' 'str2num' 'str2double' 'cconv' ... - 'gcd' 'lcm' 'fftn' 'mode' 'nnz' 'str2sym' 'factor' 'bwlabeln' 'perms'}; + 'gcd' 'lcm' 'fftn' 'mode' 'nnz' 'str2sym' 'factor' 'bwlabeln' 'perms' 'bwselect'}; verNumTh = [4 0 0]; % first version in which a modified function is not needed: if (verNum(1)