Reputation: 21
I am fairly new to programming, and started programming in python 3. The data I want to analyze have already been processed in a matlab program, and I need to export them. I don't know anything about matlab, and after searching the web I came up with this:
fileID = fopen('VarA.txt','w');
fprintf(fileID,'%.10f \n',data_1(:,1));
fclose(fileID);
fileID = fopen('varB.txt','w');
fprintf(fileID,'%.10f \n',data_1(:,2));
fclose(fileID);
This gives me 2 .txt files with x and y coordinates respectively. I have about 1000 strings (which each contains about 10k datapoints), so this seems like an awful way to do this.
My question is then; how can I export these datasets with an efficient code? For instance: I am writing a dataset to 2 different .txt files which separates the 2 variables, instead of a hash saved in 1 file.
Upvotes: 0
Views: 81
Reputation: 202
If you are interested in exporting a lot of structured numerical data, i recommend you use the HDF5 functions in matlab to write these, and the corresponding python library to read these.
To simplify the code you showed there, read about dlmwrite in the matlab help.
The way you choose (or via dlmwrite) may sound awful in the beginning, but very often will not really have an impact on the performance.
Upvotes: 1