how to read particular values using fscanf function ?

4 ビュー (過去 30 日間)
Gokul
Gokul 2013 年 10 月 7 日
コメント済み: Walter Roberson 2013 年 10 月 7 日
Hello, I have a text file as shown
1 0
2 1
3 1
4 1
5 0
.
.
.
.
147 0
148 1
149 0
150 1
I want to read only the 1's and 0's from the text file and plot them. How can i do this using fscanf. Thanks in Adv
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 10 月 7 日
You cannot not read those parts. You can, though, ignore the first column after it is read in.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 10 月 7 日
fscanf(fid, '%*d%d')
  2 件のコメント
Gokul
Gokul 2013 年 10 月 7 日
what does this mean ? Can i store 1,2,3..150 in a variable and 1's and 0's in other variable ?
Walter Roberson
Walter Roberson 2013 年 10 月 7 日
The %*d means to read an integer and discard it. Then the %d after that means to read an integer and keep it.
fscanf() and textscan() output into one single variable that you can then break up. The more general case, which would allow different data types, is textscan
datacell = textscan(fid, '%f%d' );
times = datacell{1};
tf = datacell{2};

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

カテゴリ

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