フィルターのクリア

How i load a column of float numbers to a vector from a txt file

3 ビュー (過去 30 日間)
alan
alan 2012 年 10 月 30 日
Hi,
I am a matlab beginer and i want to know how load a column of floating number from a txt file. the file hasnt chars (only numbers) as shown below:
-0.000030517578125
+0.0
-0.000030517578125
-0.000030517578125
-0.000030517578125
-0.49969482421875
-0.000030517578125
-0.000030517578125
+0.0
-0.000030517578125
-0.000030517578125
-0.000030517578125
-0.000030517578125
+0.0001220703125
thanks !!
  1 件のコメント
Sachin Ganjare
Sachin Ganjare 2012 年 10 月 30 日
You can use 'textscan' or 'textread' functions

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

回答 (2 件)

Sachin Ganjare
Sachin Ganjare 2012 年 10 月 30 日
NumHeaders = 17; %for example
NumDataLines = 1234; %for example
ColNum = 8; %for example
fmt = [ repmat('%*s',1,ColNum-1), '%f%[^\n'] ];
fid = fopen('C:\...\yourfilename.txt', 'rt');
data = textscan(fid, fmt, NumDataLines, 'HeaderLines', NumHeader);
fclose(fid);

Jan
Jan 2012 年 10 月 30 日
編集済み: Jan 2012 年 10 月 30 日
fid = fopen('C:\...\yourfilename.txt', 'r');
if fid == -1, error('Cannot open file'); end
data = fscanf(fid, '%g', [1, Inf]);
fclose(fid);

カテゴリ

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