How do I combine cells in cell array?

1 view (last 30 days)
I am trying to combine each row to be just a single string. is there anything I could do?
table =
7×13 cell array
Columns 1 through 9
{'Why'd' } {'you' } {'have' } {'to' } {'go' } {'and' } {'make' } {'have' } {'so' }
{'I' } {'see' } {'the' } {'way' } {'you're' } {'acting' } {'like' } {'you're' } {'somebody'}
{'Life's' } {'like'} {'this,' } {'have' } {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{'And' } {'you' } {'fall,' } {'and' } {'you' } {'crawl,' } {'and' } {'you' } {'break' }
{'have' } {'you' } {'take,' } {'what' } {'you' } {'get,' } {'and' } {'you' } {'turn' }
{'Honesty'} {'and' } {'promise'} {'me' } {'I'm' } {'never' } {'gonna' } {'find' } {'you' }
{'No,' } {'have'} {'no' } {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Columns 10 through 13
{'complicated?'} {0×0 double} {0×0 double} {0×0 double }
{'else' } {'gets' } {'me' } {'frustrated'}
{0×0 double } {0×0 double} {0×0 double} {0×0 double }
{0×0 double } {0×0 double} {0×0 double} {0×0 double }
{'it' } {'into' } {0×0 double} {0×0 double }
{'fake' } {'it' } {0×0 double} {0×0 double }
{0×0 double } {0×0 double} {0×0 double} {0×0 double }

Accepted Answer

Tommy
Tommy on 28 Mar 2020
Edited: Tommy on 28 Mar 2020
Try
table = table';
strjoin(table(~cellfun(@(s) isa(s,'double'), table)))
to deal with those {0x0 double} cells.
EDIT
Ah ok. There might be a better way, but see if this works:
res = cell(size(table,1),1);
for i = 1:size(table,1)
row = table(i,:);
res{i} = strjoin(row(~cellfun(@(s) isa(s,'double'), table(i,:))));
end
Great song by the way!
  2 Comments
Asheton Arnold
Asheton Arnold on 28 Mar 2020
that is close, but i need each row on its own line so i can put each line on its own line in a .txt

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!