| 1 |
function [ newstr ] = m2tstrjoin( cellstr, delimiter ) |
| 2 |
%M2TSTRJOIN This function joins a cellstr with a separator |
| 3 |
% |
| 4 |
% This is an alternative implementation for MATLAB's `strjoin`, since that |
| 5 |
% one is not available before R2013a. |
| 6 |
% |
| 7 |
% See also: strjoin |
| 8 |
|
| 9 |
%TODO: Unify the private `m2tstrjoin` functions |
| 10 |
%FIXME: differs from src/private/m2tstrjoin in functionality !!! |
| 11 |
|
| 12 |
nElem = numel(cellstr); |
| 13 |
if nElem == 0 |
| 14 |
newstr = ''; |
| 15 |
return % m2tstrjoin({}, ...) -> '' |
| 16 |
end |
| 17 |
|
| 18 |
newstr = cell(2,nElem); |
| 19 |
newstr(1,:) = reshape(cellstr, 1, nElem); |
| 20 |
newstr(2,1:nElem-1) = {delimiter}; % put delimiters in-between the elements |
| 21 |
newstr(2, end) = {''}; % for Octave 4 compatibility |
| 22 |
newstr = [newstr{:}]; |
| 23 |
|
| 24 |
end |