The leading spaces are not being counted toward the width of the fields as you're expecting.
%n.pf - will read at most n characters, starting at the beginning of a field, which does not include the spaces, it will include only the first p characters after the decimal.
You might have better luck with fixedWidthImportOptions. I didn't try this since I don't have your exact file.
>> w = [7 3 3 2 2 2 2 2 2 2 2 3 5 5 5 5 5 5 5 5 5 10 10 10 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5];
>> opts = fixedWidthImportOptions('NumVariables',numel(w),'VariableWidths',w);
>> opts = setvartype(opts,'double');
>> A = readmatrix(file,opts);
>> T = readtable(file,opts);
>> A = T.Variables;
Edit: Oops, forgot NumVariables.
1 Comment
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/465355-problem-reading-with-format#comment_711200
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/465355-problem-reading-with-format#comment_711200
Sign in to comment.