reading a txt file with rows of different length

11 ビュー (過去 30 日間)
Zinat Zarandi
Zinat Zarandi 2019 年 2 月 21 日
コメント済み: Zinat Zarandi 2019 年 2 月 22 日
Hi,
I would like to read a text file as below and I need to extract data in 'points' row. I have tried many ways but it didnt work.I appreciate if someone can guide me to find a solution.
Thanks in advance.
  2 件のコメント
Adam
Adam 2019 年 2 月 21 日
What are the 'many ways' you have tried and in what way didn't they work?
Zinat Zarandi
Zinat Zarandi 2019 年 2 月 21 日
I have found this script here and when I use this code in a cell arrey I can find data in points but in default format of text.
how can I seprate it in data?
I need to sepratet first odd num (first,third,...,n-1) as 'x' and even num (second, fourth,..,n) as 'y'.

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

回答 (1 件)

Are Mjaavatten
Are Mjaavatten 2019 年 2 月 22 日
fid = fopen(filename);
lines = textscan(fid,'%s','delimiter','\n');
fclose(fid);
lines = lines{1};
% The points data are in line 3. Start after the left bracket:
points = sscanf(lines{4}(strfind(lines{4},'[')+1:end-1),'%f,');
widths = sscanf(lines{5}(strfind(lines{5},'[')+1:end-1),'%f,');
x = points(1:2:end);
y = points(2:2:end);
  1 件のコメント
Zinat Zarandi
Zinat Zarandi 2019 年 2 月 22 日
Thank you so much. It works.

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by