Matching lines of data and negating errors in the textfile

3 ビュー (過去 30 日間)
charles atlas
charles atlas 2012 年 1 月 18 日
I am reading in a text file with the following code:
fid=fopen(filename.txt, rt);
X=textscan(fid, %s%s%s%s%s’, ‘headerlines’, 5);
I have to read in all the data as string data because when ever there is an error, the whole line that I am looking at is marked with tacs. Here is what I mean:
X{1}=
5
7
9
12
X{2}=
12
15
---
32
if the columns were all lined up in the matrix X(which is a cell array) it would look like this:
X=
5 12 12:23:51 Y 45
7 15 12:28:34 N 234
9 --- --:--:-- - 23
12 32 12:34:17 Y 87
What I want to do with this is compare the first two columns of data with the Y’s and N’s. I want to take any row of data that has an has a Y in the 4th column and leave out any row that has an N or a “-“ in it.
My end result would be individual rows or a matrix with the data I want, ex:
Xfinal=
5 12 12:23:51 Y 45
12 32 12:34:17 Y 87
Or if it is easier:
X1=
5
12
X2=
12
32
Etc.

採用された回答

Walter Roberson
Walter Roberson 2012 年 1 月 18 日
Xfinal = X( strcmp(X{4}, 'Y'), :);
  1 件のコメント
charles atlas
charles atlas 2012 年 1 月 19 日
Thank you, that was extremely helpful

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by