Effacer les filtres
Effacer les filtres

How to import .dat files (comprising multiple columns which can only be copied and pasted all at the same time) into MATLAB?

1 vue (au cours des 30 derniers jours)
I'm currently trying to import a .dat file (e.g.0002_03.dat) into MATLAB in order to logically arrange the data in a spreadsheet.
My issue is that, although the data in 0002_03.dat is nicely ordered into columns separated by spaces, it is impossible to select, copy and paste one column at a time (which would make my question redundant since, in that case, I wouldn't have to import the data into MATLAB in the first place - I could copy and paste each column into columns in Excel). If I try to select one column only, I end up selecting the entire dataset.
Thus far I have tried: import the .dat file in MATLAB using 'import' - the result is a 51x1 cell array; fid=fopen('0002_03.dat','r') which returned -1; textscan('0002_03','.xls') which returned 'Empty cell array: 1-by-0'
  6 commentaires
Bianca Elena Ivanof
Bianca Elena Ivanof le 3 Mar 2016
I've set the path datapath = 'D:\foldername\subfolder1\subfolder2\etc.' fopen(fullfile(datapath,'filename'), 'r')
ans: fid=3...
I've also tried fopen(fullfile('D:\folder\subfolder\etc.','filename'), 'r') (which is pointless since i've created a variable called datapath containing the path of the .dat file; but I've said maybe the fopen and fullfile functions will give me what I want if I rewrite the whole path again)
ans: Error: Unexpected MATLAB operator.
Does any of you guys have any idea what's going on? I have the hunch what I'm trying to achieve (see main question) is so simple, yet I can't seem to get my head around it at the moment.
Many thanks in advance

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 2 Mar 2016
Are you in the correct folder?
DataPath = 'C:\Temp'; % Adjust accordingly!
fid = fopen(fullfile(DataPath, '0002_03.dat'), 'r')
  2 commentaires
Bianca Elena Ivanof
Bianca Elena Ivanof le 2 Mar 2016
Hey Jan,
Firstly, many thanks.
Set the path and wrote fid = fopen(fullfile(DataPath, '0002_03.dat'), 'r')
Got fid = 3, which confused me even further...
Jan
Jan le 3 Mar 2016
Modifié(e) : Jan le 3 Mar 2016
fid = 3 means, that Matlab has opened the file successfully. What does confuse you at this point? I think, this is a valid point to start from.
What was the problem with the data imported by the import function? I still do not understand, which problem you are struggeling with.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by