How to create a .mat file corresponding to a .txt file, as per user input?

I have files in my Matlab directory in the form 'Phase3Subject1.txt', 'Phase3Subject2.txt',...'PhasexxSubjectyy.txt'. How do I take inputs for xx and yy from the user, and create the corresponding .mat file showing all the data stored in the .txt file? For example, if user gives input xx=2, yy=14, it should create 'Phase2Subject14.mat' file and show all the data that was stored in 'Phase2Subject14.txt'. Please give the entire code.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Jul. de 2015
Editada: Azzi Abdelmalek el 25 de Jul. de 2015
xx=2;
yy=14
filename=sprintf('Phase%dSubject%d.txt',xx,yy)
data=dlmread(filename)
save(filename,'data') % Save in a mat file

1 comentario

Thank you so much! I have another doubt. My file 'PhasexxSubjectyy.txt' contains a 2400x66 matrix of data (voltages). What do I do if I want to display all the odd numbered columns in one matrix of 2400x33, and all the even numbered columns in another matrix of 2400x33 in the file 'PhasexxSubjectyy.mat'?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by