How to convert a .mat file into tab separated .txt file?

조회 수: 199 (최근 30일)
hello_world
hello_world 2015년 2월 24일
댓글: khadicha amonova 2019년 3월 1일
Hello Friends,
I have a data matrix of real entries. I saved this matrix in MATLAB Workspace as .mat file. I want to convert it to tab separated .txt file. For this I tried the following:
load('myFile.mat')
dlmwrite('myFile.txt', myFile, 'delimiter','\t')
it does create a text file which is in notepad with name myFile.txt, however, this .txt file puts all the elements of the 1st row, 2nd row, 3rd row, etc. in one row. I do not even understand what it does. I just wanted it to remain in the same way as before, but just with tab separated and in .txt.
Though when I type the following command, it shows tab separated columns as I wanted in Command Window:
type('myFile.txt')
Please advise!
  댓글 수: 1
Stephen23
Stephen23 2015년 3월 30일
The problem is Notepad does not interpret newline-only files as newlines, but requires carriage return+newline (the PC standard). You can read more about newline standards: note that Notepad does not interpret non-PC newlines, but that Wordpad does.

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

채택된 답변

hello_world
hello_world 2015년 2월 24일
편집: hello_world 2015년 3월 30일
I found the answer to my own problem. I should have added 'newline','pc' in my command, i.e.,
dlmwrite('myFile.txt', myFile, 'delimiter','\t','newline','pc')
This gives the desired result.
  댓글 수: 7
Walter Roberson
Walter Roberson 2019년 3월 1일
Labels = ECGData.Labels;
Data = ECGData.Data;
T = table(Labels, Data);
writetable(T, 'ECGData.csv', 'WriteVariableNames', false);
This will create a .csv file in which the first column is the text label, and the remaining 65536 columns are the numeric values.
Note that this .csv file cannot be loaded into Excel, as Excel has a limit of 16384 columns.
If you wanted to get something that could be loaded into Excel, you will need to describe the format that you want for your text file.
khadicha amonova
khadicha amonova 2019년 3월 1일
thank you a lot

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

추가 답변 (2개)

Neha Chaudhary
Neha Chaudhary 2018년 4월 2일
편집: Walter Roberson 2018년 4월 2일
Nr=input('Enter no of antennas (Nt = Nr):');
Nt=Nr;
Sigma=input('0.1:1');
Pt=input('enter total power')
X=(2*randi(4,[Nt,1])-5)+i*(2*randi(4,[Nt,1])-5)%input signal*16QAM
H=(randn(Nt,Nr)+i*randn(Nt,Nr))/sqrt(2)%channel matrix H
N=(Sigma/sqrt(2))*(randn(Nt,1)+i*randn(Nt,1));%Noise matrix with variance sigma
Y=H*X+N;%output
G=inv(H'*H+Nt/Pt*eye(Nt))*H'%Pseudo inverse matrix
z=G*Y;%estimated input
Z_cap=1+2*floor(real(z)/2)+i*(1+2*floor(imag(z)/2))%slise(z)
Z_cap-X

Neha Chaudhary
Neha Chaudhary 2018년 4월 2일
편집: Walter Roberson 2018년 4월 2일
X=(2*randi(4,[Nt,1])-5)+i*(2*randi(4,[Nt,1])-5)%input signal*16QAM
dlmwrite('myFile.txt', myFile, 'delimiter','\t','newline','pc')

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by