From: Markus Due Jakobsen on
Hi

Is there someway to gather a cellarray by each row without using a loop (example 1) and without leaving whitespaces between each gathered column?


% =============================
A={'One','two';'three','four'};

% Example 1: Loop
[Row Col] = size(A);
G = cell(Row,1);
for j=1:Row
G(j) = {[char(A(j,Col-1)) char(A(j,Col))]};
end
% With the loop G looks like this, no space between "one" and "two"...
% G =
% 'Onetwo'
% 'threefour'

% Example 2: Vectorized
% Another method could be this way, but this method leaves a space between % "one" and "two"... Obs: deblank or strtrim doesn't remove the space
G1 = cellstr([char(A{:,1}) char(A{:,2})]);
% G1 =
% 'One two'
% 'threefour'

% =============================
Kind regards
Markus
From: Oleg Komarov on
"Markus Due Jakobsen" <markusdue(a)gmail.com> wrote in message <i2p724$2ml$1(a)fred.mathworks.com>...
> Hi
>
> Is there someway to gather a cellarray by each row without using a loop (example 1) and without leaving whitespaces between each gathered column?
>
>
> % =============================
> A={'One','two';'three','four'};
>
> % Example 1: Loop
> [Row Col] = size(A);
> G = cell(Row,1);
> for j=1:Row
> G(j) = {[char(A(j,Col-1)) char(A(j,Col))]};
> end
> % With the loop G looks like this, no space between "one" and "two"...
> % G =
> % 'Onetwo'
> % 'threefour'
>
> % Example 2: Vectorized
> % Another method could be this way, but this method leaves a space between % "one" and "two"... Obs: deblank or strtrim doesn't remove the space
> G1 = cellstr([char(A{:,1}) char(A{:,2})]);
> % G1 =
> % 'One two'
> % 'threefour'
>
> % =============================
> Kind regards
> Markus

A ={'One','two';'three','four'};

A1 = num2cell(A,1);
Out = strcat(A1{:})

Oleg
From: us on
"Markus Due Jakobsen" <markusdue(a)gmail.com> wrote in message <i2p724$2ml$1(a)fred.mathworks.com>...
> Hi
>
> Is there someway to gather a cellarray by each row without using a loop (example 1) and without leaving whitespaces between each gathered column?
>
>
> % =============================
> A={'One','two';'three','four'};
>
> % Example 1: Loop
> [Row Col] = size(A);
> G = cell(Row,1);
> for j=1:Row
> G(j) = {[char(A(j,Col-1)) char(A(j,Col))]};
> end
> % With the loop G looks like this, no space between "one" and "two"...
> % G =
> % 'Onetwo'
> % 'threefour'
>
> % Example 2: Vectorized
> % Another method could be this way, but this method leaves a space between % "one" and "two"... Obs: deblank or strtrim doesn't remove the space
> G1 = cellstr([char(A{:,1}) char(A{:,2})]);
> % G1 =
> % 'One two'
> % 'threefour'
>
> % =============================
> Kind regards
> Markus

one of the solutions

c={'one','two','A';'three','four','BB'};
r=arrayfun(@(x) cat(2,c{x,:}),1:size(c,1),'uni',false);
r{:}
%{
% ans =
onetwoA
% ans =
threefourBB
%}

us