From: Ulrich on
NO, C has multiple rows!
Names={'John' 'Smith';'Bob' 'Jones';'Sue' 'Brown'}
Names =

'John' 'Smith'
'Bob' 'Jones'
'Sue' 'Brown'

horzcat(Names{:})
JohnBobSueSmithJonesBrown

that's not what I am looking for. Read my question.
thx



dpb <none(a)non.net> wrote in message <huqn3k$klk$1(a)news.eternal-september.org>...
> Ulrich wrote:
> ...
>
> > I have a variable cell array (n,m) of strings e.g.:
> > C= 'ab' 'egh' 'zgr',.....
> > ......
> > the result shoud be:
> >
> > D= 'abeghzgr.....'
> > 'hlkdzg....'
> > .......
> > ......
> >
> > to me, shoud be 'horzcat',like D=horzcat(C). But does not work.
> > Please post only a solution without loops
>
> Picky, aren't we...
>
> >> C= { 'ab' 'egh' 'zgr'};
> >> horzcat(C{:})
> ans =
> abeghzgr
> >>
>
> Dereference cell cotnents...
>
> --
From: dpb on
Ulrich wrote:
> NO, C has multiple rows!
....

> that's not what I am looking for. Read my question.
....

Use a loop...

--
From: Oleg Komarov on
dpb <none(a)non.net> wrote in message <huqnvi$irk$1(a)news.eternal-september.org>...
> Ulrich wrote:
> > NO, C has multiple rows!
> ...
>
> > that's not what I am looking for. Read my question.
> ...
>
> Use a loop...
>
> --

a = {'ab' 'egh' 'zgr'
'hlk' 'd' 'zg'};
sza = size(a);
rowLen = cellfun('prodofsize',a);
maxLen = max(rowLen(:));
numBlanks2Pad = maxLen-rowLen;

a = reshape(arrayfun(@(x,y) [y{:} blanks(x)],numBlanks2Pad,a,'un',0).',1,[]);
a = strrep(cellstr(reshape([a{:}].',[],sza(1)).'),' ','')

a =
'abeghzgr'
'hlkdzg'

I think I'm doing unnecessary transpose operations...but the result is correct...

oleg
From: Ulrich on
anyhow, thx dpd!

It seams to me that Matlab is not able to perform that within one function call!
However, can be that others are looking for a (fast) solution to find unique rows of a cell array of strings or single numbers, then the following code could be useful:

function set_member=find_str_members(A_mat,max_members)
if ~iscell(A_mat)
A_mat=num2cell(A_mat);
end
A_cell=cellfun(@num2str, A_mat,'uni',0);
A_cat=[];
for j=1:size(A_cell,2);
A_cat=cellstr([char(A_cat) char(A_cell{:,j})]);
end
A_cat=strrep(A_cat,' ','');
[d1,c_members,v]=unique(A_cat);
clear d1;
if (c_members>max_members)
set_member=[];
else
set_member=v;
end




dpb <none(a)non.net> wrote in message <huqnvi$irk$1(a)news.eternal-september.org>...
> Ulrich wrote:
> > NO, C has multiple rows!
> ...
>
> > that's not what I am looking for. Read my question.
> ...
>
> Use a loop...
>
> --
From: Oleg Komarov on
"Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <huqpo4$bla$1(a)fred.mathworks.com>...
> dpb <none(a)non.net> wrote in message <huqnvi$irk$1(a)news.eternal-september.org>...
> > Ulrich wrote:
> > > NO, C has multiple rows!
> > ...
> >
> > > that's not what I am looking for. Read my question.
> > ...
> >
> > Use a loop...
> >
> > --
>
> a = {'ab' 'egh' 'zgr'
> 'hlk' 'd' 'zg'};
> sza = size(a);
> rowLen = cellfun('prodofsize',a);
> maxLen = max(rowLen(:));
> numBlanks2Pad = maxLen-rowLen;
>
> a = reshape(arrayfun(@(x,y) [y{:} blanks(x)],numBlanks2Pad,a,'un',0).',1,[]);
> a = strrep(cellstr(reshape([a{:}].',[],sza(1)).'),' ','')
>
> a =
> 'abeghzgr'
> 'hlkdzg'
>
> I think I'm doing unnecessary transpose operations...but the result is correct...
>
> oleg

A simpler solution (to my opinion):

cellstrhcat(a)
ans =

'abeghzgr'
'hlkdzg'


function Out = cellstrhcat(cellIn)
% Num of rows
numRows = size(cellIn,1);
% Preallocate
Out = cell(numRows ,1);
% Loop
for r = 1:numRows
Out{r} = [cellIn{r,:}];
end
end

Oleg
 |  Next  |  Last
Pages: 1 2 3
Prev: F28335 plus TIMER1
Next: parking sensor very much