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

201 visualizaciones (últimos 30 días)
hello_world
hello_world el 24 de Feb. de 2015
Comentada: khadicha amonova el 1 de Mzo. de 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 comentario
Stephen23
Stephen23 el 30 de Mzo. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

hello_world
hello_world el 24 de Feb. de 2015
Editada: hello_world el 30 de Mzo. de 2015
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 comentarios
Walter Roberson
Walter Roberson el 1 de Mzo. de 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.

Iniciar sesión para comentar.

Más respuestas (2)

Neha Chaudhary
Neha Chaudhary el 2 de Abr. de 2018
Editada: Walter Roberson el 2 de Abr. de 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
Neha Chaudhary el 2 de Abr. de 2018
Editada: Walter Roberson el 2 de Abr. de 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')

Community Treasure Hunt

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

Start Hunting!

Translated by