フィルターのクリア

Importing a text file with two headers and data so that the headers are the variable names

4 ビュー (過去 30 日間)
I have a large amount of data and usually just manually import it in by deleting the units row (2nd row) and using the first row as the variable name. But I would like to make a script to make my life easier, but have wasted too much time already trying to figure it out.
Basically, is there an easy script to import a .txt file, delete the second row and use the first row as the variable names of the numerical data arrays?
  3 件のコメント
Andrew
Andrew 2012 年 1 月 4 日
here is an example of the data, I do not care about the units, and would like the the column headers to be the varible names of the array
Temp_pre_bpv_Value Air_pres_filtered Actual_fuel_value
K kPa mg
708.1 289 264.5
707 289.2 263.5
708.1 289.7 263.6
707 289.9 263.7
708.1 289.9 263.7
709.1 289.1 170.2
709.1 285.6 0
Thank You.
Andrew
Andrew 2012 年 1 月 4 日
Basically I would like this:
BPV_Temp
Kelvin
708
709
800
To look Like this:
BPV_Temp
708
709
800

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

採用された回答

Teja Muppirala
Teja Muppirala 2012 年 1 月 4 日
There are a lot of ways to deal with reading in data. This is one imaginative way of doing it, but I think it should work. (Here I assume each value is separated by a single space, and each value is read in as a double). Maybe someone has a simpler idea.
fid = fopen('myfile.txt','r');
firstline = fgetl(fid);
numvars = numel(strread(firstline,'%s'));
fgetl(fid); %<-- Skip the second line
data = textscan(fid,repmat('%f',1,numvars));
eval(['[' strrep(firstline,' ',',') '] = deal(data{:})'])
fclose(fid);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by