How to convert 10x10 matrix to X, Y, Z txt file
Show older comments
This 10x10 matrix is an array of several Z values (i.e. element 1x1 is z=5, element 3x6 is z=2, etc.). How can I output this matrix data to a text file that reads:
- 1 1 5
- 1 2 3
- 1 3 11
- ...
- 10 9 6
- 10 10 3
I am relatively new to MATLAB, so please excuse the naivety of this question.
Many thanks.
3 Comments
Wayne King
on 27 Jan 2014
Can you please clarify what you mean by element 1x1 is z=5, element 3x6 is z=2, . You have a 10x10 matrix in MATLAB, do you simply want to write this 10x10 matrix to a text file as is? Or do you want to reformat it when you write it. Please show an example of a 10x10 matrix and how you want it to appear in the text file.
Joseph
on 27 Jan 2014
Azzi Abdelmalek
on 27 Jan 2014
What kind of trouble?
Answers (1)
Azzi Abdelmalek
on 27 Jan 2014
Edited: Azzi Abdelmalek
on 27 Jan 2014
If A is your matrix
A=[1 1 1; 1 2 2; 1 3 3; 1 4 4; 1 5 5; 2 1 1; 2 2 2; 2 3 3;5 5 5]
dlmwrite('file_name.txt',A,'delimiter','\t')
%or
A=[1 1 1; 1 2 2; 1 3 3; 1 4 4; 1 5 5; 2 1 1; 2 2 2; 2 3 3;5 5 5]
dlmwrite('file_name.txt',A,'delimiter','\t','newline','pc')
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!