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

7 visualizaciones (últimos 30 días)
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 comentarios
Bianca Elena Ivanof
Bianca Elena Ivanof el 3 de Mzo. de 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

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 2 de Mzo. de 2016
Are you in the correct folder?
DataPath = 'C:\Temp'; % Adjust accordingly!
fid = fopen(fullfile(DataPath, '0002_03.dat'), 'r')
  2 comentarios
Bianca Elena Ivanof
Bianca Elena Ivanof el 2 de Mzo. de 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 el 3 de Mzo. de 2016
Editada: Jan el 3 de Mzo. de 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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by