フィルターのクリア

Loading ascii data file with headers

15 ビュー (過去 30 日間)
David Polcari
David Polcari 2013 年 4 月 25 日
コメント済み: Maryam Huck 2021 年 5 月 1 日
Hi,
I am having trouble loading a data file into matlab with some headers. Here is an sample of what I have:
Series_6_2
Sweep_6_2_1 4.924117200E+04 13:40:41.171
"Index" "Distance[m]" "I-tip[A]"
0 0.000000000E+00 1.647949222E-09
1 3.100000000E-07 1.665649396E-09
2 6.200000000E-07 1.679992701E-09
3 9.300000000E-07 1.701660146E-09
4 1.240000000E-06 1.721191412E-09
5 1.550000000E-06 1.745300238E-09
6 1.860000000E-06 1.777038627E-09
7 2.170000000E-06 1.811218286E-09
8 2.480000000E-06 1.844787545E-09
9 2.790000000E-06 1.878662115E-09
10 3.100000000E-06 1.914672865E-09
11 3.410000000E-06 1.954650886E-09
12 3.720000000E-06 1.990966725E-09
I would like to have just a matrix with the numerical values. Any ideas?
  1 件のコメント
Maryam Huck
Maryam Huck 2021 年 5 月 1 日
Hi, How to open the data, when the structure given above, repeats several time? i.e.:
Header = Parameters
Data
Header = Parameters
Data
Header = Parameters
Data
Header = Parameters
Data
How to then extract all the data, each in different rows ?

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

採用された回答

Matt Kindig
Matt Kindig 2013 年 4 月 25 日
This should do it
fid = fopen('path/to/your/file.txt', 'rt');
Data = textscan(fid, '%d %f %f', 'headerLines', 3, 'CollectOutput', true);
fclose(fid);
Data= cell2mat( Data);
  2 件のコメント
David Polcari
David Polcari 2013 年 4 月 25 日
Quick follow up: I am trying to use inputdlg to prompt the user to enter the filename:
filename = input('Enter filename with extension: ','s');
I want to use filename in the rest of your lines but can't seem to get it to work. Any ideas?
Iain
Iain 2014 年 2 月 3 日
uigetfile would be better than filename. Just remember to concatenate the path & filename it returns into "filename", then,
fid = fopen(filename,'rt');

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

その他の回答 (2 件)

Cedric
Cedric 2013 年 4 月 25 日
編集済み: Cedric 2013 年 4 月 25 日
The following would be an option:
[index, distance, tip_A] = textread('myFile.txt', '%d %f %f', 'headerlines', 3) ;
  3 件のコメント
Matt Kindig
Matt Kindig 2013 年 4 月 25 日
The textscan() function (that I've used below) will automatically stop once the pattern is no longer found, which means that it should ignore the text at the bottom of the file. I'm not sure about textread() though.
Cedric
Cedric 2013 年 4 月 25 日
編集済み: Cedric 2013 年 4 月 25 日
Yes, until they implement the 'footerlines' option for TEXTREAD ;-), Matt's solution with TEXTSCAN is the way to go if you have a footer.

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


itay
itay 2014 年 2 月 3 日
i recommend you to use importdata. try it and tell me.

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by