How to read a text file into a char array
53 views (last 30 days)
Show older comments
Paolo Binetti
on 22 Jan 2017
Commented: Paolo Binetti
on 22 Jan 2017
This is probably trivial, but I have not found an easy way to convert a text file of n lines and m columns (sample attached) into a char array of the same shape. The only way that might work for me is an n-long for-loop of "fscanf", but I do not know n beforehand, and I figure there must be a simpler and faster vectorized command, which I ignore (I tried fileread and textread to no avail).
0 Comments
Accepted Answer
Walter Roberson
on 22 Jan 2017
temp = regexp(fileread('sample_input.txt'), '\r?\n', 'split');
output = vertcat(temp{:});
More Answers (0)
See Also
Categories
Find more on Cell Arrays 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!