Cell array to 1x1 Vector/Cell

4 visualizzazioni (ultimi 30 giorni)
tom rawr
tom rawr il 1 Mar 2012
Commentato: Stephen23 il 1 Dic 2023
Hi
If I have a cell array such as c = {'word1','word2'}
How can I take this and convert it into a 1x1 cell that has all the words in the 1 cell but seperated by a space? Is this possible?
So say the 1x1 matrix would be: word1 word2
Thanks
edit: cell2mat doesnt give me the space in between. it does "word1word2"
  1 Commento
Stephen23
Stephen23 il 1 Dic 2023
Since R2016b:
c = {'word1','word2'}
c = 1×2 cell array
{'word1'} {'word2'}
join(c)
ans = 1×1 cell array
{'word1 word2'}

Accedi per commentare.

Risposte (2)

Oleg Komarov
Oleg Komarov il 1 Mar 2012
This is one way:
c2 = deblank(sprintf('%s ',c{:}));

G A
G A il 1 Mar 2012
c1 = [c{1},' ',c{2}]

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by