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.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 25 Jul. 2015
Bearbeitet: Azzi Abdelmalek am 25 Jul. 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 Kommentar

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'?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by