Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.