MATLAB: How to use repmat in the textscan()

repmattextscan

I use the textscan() to read complex text files as following code
clear, clc, close
fid = fopen('Data.txt');
C = textscan(fid,'%s %s %s %s %s %s %s %s %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %d %f %d %f %d %d %f %f %f %d %f %d %d %d %f %f %f %f %f %d %f %d %d %f %d %f %f %d %d %f %f %f %d %f %d %d %f %f %d %d %f %f %f %d %f %d %d %f %d %d %d %f %d %d %d %d %d','HeaderLines',3,'Delimiter',' ')
fclose(fid);
I would like to know how to put repmat in the textscan() function instead of typing format repeat many times as above.
Please advise

Best Answer

fmtchars = 'sfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdf';
fmtcounts = [9 14 1 1 1 1 2 3 1 1 3 5 1 1 2 1 1 2 2 3 1 1 2 2 2 3 1 1 2 1 3 1];
expanded_chars = repelem(fmtchars, fmtcounts);
fmt = reshape([repmat('%', 1, length(expanded_chars)); expanded_chars], 1, []);
C - textscan(fid, fmt, 'HeaderLines',3,'Delimiter',' ');
The spaces are not needed. Your delimiter is questionable as well, as multiple whitespace is the default delimiter.