Create a text file and writing a 2D list into it.

1 visualización (últimos 30 días)
Isaac Mussali M
Isaac Mussali M el 21 de Oct. de 2019
Respondida: Sid Singh el 24 de Oct. de 2019
Hello there! I have two variables (X and Y) each containing a thousand elements in the form 1x1000. My goal is to create a text file that looks like this:
X---------------------------------Y
x1 y1
x2 y2
x3 y3
x4 y4
and so on and so on
I´ve tried with the following code:
resultadosreto=fopen('resultadosreto.txt','w');
fprintf(resultadosreto,'X-------------------Y\n');
fprintf(resultadosreto,'%2.2f %4.3f\n',pfinalx,pfinaly);
However, MATLAB creates a text file like this
X---------------------------------Y
x1 x501
x2 x502
x3 x503
.....until 500 until a 1000
x500 x1000
then it prints the list on variable Y in the same format.
Any help would be appreciated!

Respuestas (1)

Sid Singh
Sid Singh el 24 de Oct. de 2019
Hi, if we see the data, we can give more inputs. In the meanwhile, can you please try to iterate over pfinalx and pfinaly and use fprintf to write each line one by one?

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by