Using fopen, textscan for TXT file but each line cut off at space. How to resolve the issue?

I have a large txt file containing the filepaths for specified files.
Ex:
H:\Vicon_data\modified2AFC\Clarkson 2AFC\M29AA216\M29AA216afc01c1asfh_0000.3LA
My code:
%read the text file
fileID=fopen('Master_inventory.txt');
inventory = textscan(fileID,'%s %*[^\n]');
d = inventory{1};
c = cellstr(d)
Result in command window:
'H:\Vicon_data\modified2AFC\Clarkson'
NOTE: The example path is one of +28000, which are distributed into different folders, so I can't go back and delete the spaces from the folder names.

 채택된 답변

I'm partial to
inventory=textread('Master_inventory.txt', '%s', 'delimiter', '\n', 'whitespace', '');
as it saves the extra f[open|close] step required in textscan
Your problem is the single %s will interpret up to a whitespace character as the string and then you told it to skip the remainder of the line.
The above to switch delimiter to newline and eliminate whitespace parsing works with textscan, too, though, if you prefer to stick with it.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

질문:

2014년 7월 15일

답변:

dpb
2014년 7월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by