MATLAB: Data save, dlmwrite, and data read load, save several effective digits; wrong use of load cannot read the MAT file mndata.mat. Not a binary MAT-file.

Environment: matlab2019b

1. Data storage

When we need to save the data generated by matlab and save it as a .txt or .mat file, we can use fixed functions: save, dlmwrite or fopen+fprintf+fclose. The specific usage method can be found in the help The example that comes with matlab. I used the data file generated by dlmwrite this time, and the result of the value generated by it is different from that of save. The following is the comparison:

The following is a txt file stored in save (3w+ data):

The one below is a txt file (3w+ data) stored by dlmwrite. The value is different because I ran the program again to generate a new result:

2. Data reading

When using load to read the saved .mat file data, the following error occurred:

Unable to read MAT-file E:\work\MATLAB\perject\dete202212226\mndata.mat. Not a binary MAT-file. Try load -ASCII to read it as text.

You need to change load mndata.mat in the program to load mndata.mat -ascii to read normally, and you need to pay attention to the path must be in English.

During the debugging process, it is found that the final output result of reading the .txt file is the same as that of reading the .mat file, and there is no need to add a suffix when using load mndata.txt.

Replenish:

dlmwrite keeps 5 significant digits:

Guess you like

Origin blog.csdn.net/weixin_46152123/article/details/128615780