フィルターのクリア

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

1 回表示 (過去 30 日間)
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 件のコメント
Bianca Elena Ivanof
Bianca Elena Ivanof 2016 年 3 月 3 日
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
Jan
Jan 2016 年 3 月 3 日
Please post the complete error message.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2016 年 3 月 2 日
Are you in the correct folder?
DataPath = 'C:\Temp'; % Adjust accordingly!
fid = fopen(fullfile(DataPath, '0002_03.dat'), 'r')
  2 件のコメント
Bianca Elena Ivanof
Bianca Elena Ivanof 2016 年 3 月 2 日
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 2016 年 3 月 3 日
編集済み: Jan 2016 年 3 月 3 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by