How to read Spaces from a file in Matlab? -
i want read characters file including spaces, trying
fileread = textread('myfile.txt', '%c'); disp('characters total') disp(length(fileread))
but result not correct because counting characters except space.
so how do that, appreciated?
i want read file spaces.
so on textread
(or better alternative textscan
) isn't super clear on how %c
format specifier handles whitespace.
if use single %c
, going read one character @ time in scenario, whitespace still going treated delimiter since falls between 2 single-character matches.
what documentation referring %c
matching whitespace if specify expected length %c
specifier (%<length>c
), whitespace included in match.
textread('z.txt', '%12c') % name z
if want read in entire file character array, use fread
'*char'
data type low-level function accessing file contents if don't need parse them @ all.
fid = fopen('z.txt', 'r'); data = fread(fid, '*char').'; disp(numel(data))
if want use textread
, option use %s
(string) format specifier instead of character specifier , set 'whitespace'
parameter ''
not treat spaces whitespace , therefore delimeter.
textread('z.txt', '%s', 'whitespace', '')
Comments
Post a Comment