The Math Forum

Search All of the Math Forum:

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

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

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

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


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

% =============================

% 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))]};
% 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

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.