How to convert 10x10 matrix to X, Y, Z txt file

조회 수: 1 (최근 30일)
Joseph
Joseph 2014년 1월 27일
편집: Azzi Abdelmalek 2014년 1월 27일
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
Joseph
Joseph 2014년 1월 27일
Sorry for the lack of clarity.
Let's say I have a 5x5 matrix as follows:
[1 2 3 4 5; 1 2 3 4 5; 1 2 3 4 5; 1 2 3 4 5; 1 2 3 4 5],
where each matrix element represents some arbitrary Z value.
I would like to output the array to the following format:
[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]
What function should I use to accomplish this? I tried using dlmwrite, as Mr. Azzi Abdelmalek suggested, but am still having some trouble.
Again, please excuse my naivety, as I am still learning the basics of MATLAB.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 27일
What kind of trouble?

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 27일
편집: Azzi Abdelmalek 2014년 1월 27일
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')

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by