reading a txt file with rows of different length
20 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Are Mjaavatten
on 22 Feb 2019
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);
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!