フィルターのクリア

Use of fopen,fscanf and fclose.

5 ビュー (過去 30 日間)
Massilon Toniolo da Silva
Massilon Toniolo da Silva 2017 年 5 月 21 日
コメント済み: Walter Roberson 2017 年 5 月 22 日
Dear colleagues,
I have been trying to select rows and columns of a data set in text file. The data I have got is displayed as a 90-by-4 matrix. I would need to have a matrix consisting of all rows but only column 2. The way I have tried to carry it out is as follows:
fid = fopen('chf201.txt','r');
data=fscanf(fid,'%g', [4,inf]);
fclose(fid);
result=data(2,:);
result =
0
Attempted to access data(2,:); index out of bounds because numel(data)=1.
Could you please help me in this matter, since I did not get the 90-by-1 matrix as the result? Kind regards, Massilon
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 21 日
Is there a header line on the file? What does the first two lines look like?
dpb
dpb 2017 年 5 月 21 日
Besides whatever is wrong in your attempt to read the data (probably something like what Walter has suggested would be a very good guess),
result=data(2,:);
would be the 2nd row, all columns, not the second column.
Try importdata for the easy-peasy way to read a text file with header and see if it can infer the format automagically.

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

回答 (2 件)

Image Analyst
Image Analyst 2017 年 5 月 21 日
Try this:
data = importdata('chf201.txt');
column2 = data(:, 2);

Massilon Toniolo da Silva
Massilon Toniolo da Silva 2017 年 5 月 21 日
Dear Stephen Cobeldick,
I am sorry for the delay. Now I am sending the files annotations_nsr001 and annotations_chf201.txt both from Physionet.org (Normal Sinus Rhythm RR Intervals Database). I thank you very much for any help. Kind regards, Massilon
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 22 日
I recommend using readtable() for those, if you have R2013b or later. Especially if you have R2014b or later, readtable() will take care of creating datetime objects out of the first column.

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by