Read data from .dat file

4 ビュー (過去 30 日間)
Elduderino
Elduderino 2015 年 12 月 24 日
コメント済み: Elduderino 2015 年 12 月 24 日
Hey,
I am trying to read some data from a .dat file, by using the textscan function. The Problem is, that MATLAB outputs me a cell array where the cells contain the whole column of my data and I am not able to adress each element individually, which I will need for further evaluation. Sb knows what I am missing here?
Merry Christmans
Code and files:
datacell = textscan(fid, '%u %u %f64 %f64 %f64','HeaderLines', 1);
Data File:
% track# exppar1[Hz] lcut[dB HL] mlow[CU/dB] mhigh[CU/dB]
1 250.00000000 54.22407002 0.40618241 0.88538138
2 500.00000000 65.67426102 0.35505814 1.03196552
3 1000.00000000 68.89377754 0.33789152 1.14795756
4 2000.00000000 59.92227307 0.36044833 0.99198012
5 4000.00000000 63.79115269 0.39970735 3.14824276
6 6000.00000000 56.08308046 0.46312449 1.20653864
output of datacell{1}
ans =
1
2
3
4
5
6

採用された回答

Kirby Fears
Kirby Fears 2015 年 12 月 24 日
You've given textscan directions to read 5 columns where the first two are %u (integers) and the next three are %f64 (doubles). Considering that you are specifying data types per column, Matlab has to give you each column separately. It's standard to put the columns together into a cell array.
You can access row 5 of column 1 by indexing twice as follows:
datacell{1}(5)
ans =
5
Does this solve your problem? What else are you trying to do with the data?
  4 件のコメント
Kirby Fears
Kirby Fears 2015 年 12 月 24 日
編集済み: Kirby Fears 2015 年 12 月 24 日
If you're willing to make each column the same datatype, you can read your data into a double array as follows:
dataArray = textscan(fid, '%n %n %n %n %n',...
'HeaderLines', 1,'CollectOutput',true);
dataArray = dataArray{1};
Elduderino
Elduderino 2015 年 12 月 24 日
Thanks was exactly what I was looking for, and didn't expect this cell array + 'regular array' syntax.
I guess I am just going to make some graphs, standard deviation and maybe look for correlation. Nothing fancy :)
Thanks again and a merry Christmas you all!

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

その他の回答 (0 件)

カテゴリ

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