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

1 次查看(过去 30 天)
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!

回答(1 个)

Sid Singh
Sid Singh 2019-10-24
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?

产品

Community Treasure Hunt

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

Start Hunting!

Translated by