How to covert a cell to multiple line string?

8 visualizaciones (últimos 30 días)
Sundeepan
Sundeepan el 26 de Sept. de 2016
Editada: Sundeepan el 26 de Sept. de 2016
I have a cell with one coloumn and varing number of rows. The cell contains alpha-numeric string. I want to convert this cell into a multiple line string with each cell content as one line of the string.
How can this be acheived ?
  1 comentario
Jan
Jan el 26 de Sept. de 2016
Cells are arrays. Therefore all columns have the same number of rows. I assume, the contents of the cell elements are char vectors with a different number of clumns.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 26 de Sept. de 2016
If you use CHAR you get a CHAR matrix padded with blanks on the right side. You can get "multi-line" also by inserting line breaks:
CellString = {'some'; 'strings'; 'to'; 'convert'; 'to'; 'a'; 'char'; 'array'}
CharString = sprintf('%s\n', CellString{:});
  1 comentario
Sundeepan
Sundeepan el 26 de Sept. de 2016
Editada: Sundeepan el 26 de Sept. de 2016
Thanks Guillaume & Jan for the solution. I tried out both the solutions suggested and find adding line breaks more effective.
The reason to change the cell content to multiline string was to define the model properties for a Simulink model(multiple m files).

Iniciar sesión para comentar.

Más respuestas (1)

Guillaume
Guillaume el 26 de Sept. de 2016
Use char:
cellarrayofstring = {'some'; 'strings'; 'to'; 'convert'; 'to'; 'a'; 'char'; 'array'}
chararrayofstring = char(cellarrayofstring)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by