How to turn data from text file into cell array?

So I've got this sample.txt and I'm told that the first integer is to be the number of triangles there are on the array while the following numbers are the width and height respectively.
So far I'm at:
FID=fopen('sample.txt','r');
A=fscanf(FID,'%s');
and I get the string but it has no spaces. I want the scan to ignore the 1st number and make the rest into a 2 column matrix so I can used the height and width to create the area. Please help!

 採用された回答

Michael Haderlein
Michael Haderlein 2015 年 5 月 7 日
編集済み: Michael Haderlein 2015 年 5 月 7 日

0 投票

What is rows 2-18? Under the assumption that we can ignore them, just use textscan and take them as headerlines:
>> fid=fopen('sample.txt');
>> data=textscan(fid,'%f%f','headerlines',18);
>> fclose(fid);
>> width=data{1};
>> height=data{2};
However, only 100 rows are found then instead of 112. But as some of the rows before row 19 have more/less than 2 columns, they don't seem to have the same meaning.

3 件のコメント

Japoe25
Japoe25 2015 年 5 月 7 日
Hello,
So what they told me is every number after the first one is the width and height but alternating, 1st width: 5 1st height:10
thank you :)
Michael Haderlein
Michael Haderlein 2015 年 5 月 7 日
>> fid=fopen('sample.txt');
>> data=textscan(fid,'%f','headerlines',1);
>> fclose(fid);
>> width=data{1}(1:2:end);
>> height=data{1}(2:2:end);
Japoe25
Japoe25 2015 年 5 月 7 日
That's much better! thank you kind sir, sorry for duplicating, I was getting impatient :(

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by