How do i skip several lines in an open TEXT file?

Hello.
I attached a picture of my text file, to emphasize:
Frame Ty Tx
============================
1 509.50 1141.50
2 509.50 1141.50
3 509.50 1139.50
4 511.50 1139.50
I need to skip the headlines and i need an easy way of reading the remaining lines of the file, i.e. the numbers.
for example i need an easy way of obtaining only the numbers :
1 509.50 1141.50
2 509.50 1141.50
3 509.50 1139.50
4 511.50 1139.50
And then to easily use each row and to obtain the data from the remaining file as obtaining numbers from a matrix(i.e skip the uneaven spaces between each coulmn :
C{1}:
1
2
3
4
C{2}:
509.50
509.50
509.50
511.50
C{3}:
1141.50
1141.50
1139.50
1139.50
Thank you.

回答 (1 件)

Anna
Anna 2015 年 8 月 23 日

0 投票

Open the .txt file using fopen:
fid1 = fopen('filename','r');
Then I suggest using textscan to read your data. You can use 'HeaderLines' to specify how many opening lines to skip:
data = textscan(fid1,'%f %f %f','HeaderLines',2)
This will read your data into a cell array. If you wish to access row,col indices, you can convert this to a matrix:
c = cell2mat(data);

3 件のコメント

omer
omer 2015 年 8 月 23 日
Hey Anna, thank you for your answer, but i encounter a problem after i use the textscan function . the problem is showen in the attached picture. What should i do?
Anna
Anna 2015 年 8 月 23 日
編集済み: Anna 2015 年 8 月 23 日
Your system must be set to hebrew and MATLAB uses this as its default encoding. Try this
fid1 = fopen('TargetLocation.txt', 'r', 'n', 'US-ASCII','HeaderLines',2); to open the file.
omer
omer 2015 年 8 月 23 日
I tried but its too many input arguments for the fopen function. And then i used it like this :
and its fixed the problem but i still recieve a zero matrix in C. :P

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

カテゴリ

ヘルプ センター および File ExchangeData Import and Export についてさらに検索

質問済み:

2015 年 8 月 23 日

編集済み:

2015 年 8 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by