Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to gather a cell array of strings
Replies: 2   Last Post: Jul 28, 2010 8:39 AM

 Messages: [ Previous | Next ]
 Markus Due Jakobsen Posts: 43 Registered: 4/29/08
How to gather a cell array of strings
Posted: Jul 28, 2010 8:16 AM

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

Date Subject Author
7/28/10 Markus Due Jakobsen
7/28/10 Oleg Komarov
7/28/10 us