Converting a matrix of strings to a txt file

1 visualización (últimos 30 días)
Paramonte
Paramonte el 21 de Feb. de 2020
Comentada: Paramonte el 21 de Feb. de 2020
Hi there!
I have a mtarix of strings x_mtarix:
x_matrix =
5×3 string array
"A" "B" "C"
"AA" "BB" "CC"
"AAA" "BBB" " "
"AAAA" " " " "
"AAAAA" " " " "
which I would like to save in a text file that woul contain the x_matrix values keping the same appearance:
A B C
AA BB CC
AAA BBB
AAAA
AAAAA
I have used an assortment of variations of:
fid = fopen('output.txt','wt');
fprintf(fid,'%s\n',x_matrix);
fclose(fid);
But I dont quite get the results I want
Thanks in advance

Respuesta aceptada

Stephen23
Stephen23 el 21 de Feb. de 2020
Editada: Stephen23 el 21 de Feb. de 2020
  1. the format string need to have 3 conversion operators (or as many as you want on each line).
  2. the matrix needs to be tranposed.
For example:
fmt = repmat('%8s ',1,3);
fmt = [fmt(1:end-1),'\n'];
fprintf(fid, fmt, x_matrix.')

Más respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by