Create a text file and writing a 2D list into it.
1 view (last 30 days)
Show older comments
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!
Answers (1)
Sid Singh
on 24 Oct 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?
0 Comments
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!