How to save a text file as a .mat file?
90 views (last 30 days)
Show older comments
Hi,
I have a text file having data with each row having the format: a1,a2,a3,a4. I have close 2k such rows. I need to save the full text file as a .mat file. How do I get that? I already tried tetxscan but I run into cell within cell issue. Appreciate help.
0 Comments
Answers (4)
KSSV
on 8 Nov 2018
Edited: KSSV
on 8 Nov 2018
data = importdata('myfile) ;
save data.mat -v7.3
Using textscan
fid = fopen(myfile) ;
S = textscan(fid,'%f %f %f %f') ;
fclose(fid) ;
a1 = S{1} ; a2 = S{2} ; a3 = S{3} ; a4 = S{4} ;
save data.mat -v7.3 ;
4 Comments
KSSV
on 9 Nov 2018
data = importdata('data.txt') ; % you can use load also
save data.mat -v7.3
It is giving you the full data in text file.
madhan ravi
on 8 Nov 2018
Matrix=load('sample.txt') %assuming text file is numeric
save sample.mat Matrix
0 Comments
CuriousThinker
on 9 Nov 2018
Edited: CuriousThinker
on 9 Nov 2018
1 Comment
Stephen23
on 10 Nov 2018
"I was able to solve it using csvread()"
Don't forget to accept the answer that showed you how to use csvread.
See Also
Categories
Find more on Text Files 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!