How to convert a .mat file into tab separated .txt file?
189 views (last 30 days)
Show older comments
hello_world
on 24 Feb 2015
Commented: khadicha amonova
on 1 Mar 2019
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 Comment
Stephen23
on 30 Mar 2015
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.
Accepted Answer
hello_world
on 24 Feb 2015
Edited: hello_world
on 30 Mar 2015
7 Comments
Walter Roberson
on 1 Mar 2019
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.
More Answers (2)
Neha Chaudhary
on 2 Apr 2018
Edited: Walter Roberson
on 2 Apr 2018
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
on 2 Apr 2018
Edited: Walter Roberson
on 2 Apr 2018
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')
0 Comments
See Also
Categories
Find more on Spreadsheets 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!