如何将文本文件保存到.mat文件?

时间:2018-11-08 08:00:59

标签: python-2.7 matlab text-files mat-file

如何使用MATLAB或Python将“ .txt”文件另存为“ .mat”文件? 我尝试使用textscan()(在MATLAB中)和scipy.io.savemat()(在Python中)。两者都没有帮助。

我的文本文件的格式为:value1,value2,value3,valu4(每行),并且有1000多个行。

感谢任何帮助。预先感谢。

3 个答案:

答案 0 :(得分:3)

您可以使用textscan读取文件,并使用save将变量保存到.mat文件中

fid = fopen('yourTextFile.txt');
C = textscan(fid,'%f %f %f %f');
fclose(fid);
% maybe change the cells from `C` to a single matrix
M = cell2mat(C);
save('myMatFile.mat','M');

这行得通,因为您的文件似乎具有固定格式。 看看thisthis

答案 1 :(得分:0)

我可以使用csvread()使其工作,如下所示:

file = csvread('yourTextFile.txt');
save('myMatFile.mat','file');

答案 2 :(得分:-3)

如果您需要更改文件格式: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="msg_archivedropdown">show div</div> <button onclick="colorbubble()">change</button>