hello
this is an alternative that worked on my pc. There may be better coding options, I admit I had a bit of a hard time figuring out why writecell did not give the expected result with an array of cells of different size. Maybe someone else will bring this later on
but so dar so good :
and also I add natsortfiles to make sure the input files are sorted according to the natural order (from the numerical values in the filename)
fileDir = cd;
outfile = 'MASTER.xlsx';
fileNames = dir(fullfile(cd,'*.csv')); % get list of files in directory
fileNames_sorted = natsortfiles({fileNames.name}); % sort file names into order
M= length (fileNames_sorted);
for f = 1:M
raw = csvread( fullfile(fileDir, fileNames_sorted{f}));
out{f} = raw(:,2);
end
% padd NaNs for shorter arrays - do we have another solution ?
maxSize = max(cellfun(@numel,out)); %# Get the maximum vector size
fcn = @(x) [x ; nan(maxSize-numel(x),1)]; %# semicolon here
rmat = cellfun(fcn,out,'UniformOutput',false); %# Pad each cell with NaNs
% writecell(rmat,fullfile(cd,outfile)); % why this does not work ??
writematrix(cell2mat(rmat),fullfile(cd,outfile)); % work around
