Could you simplify your input by creating the string first using MATLAB code and then use dlmwrite to add a single string? This might make it easier.
For clarity, here is what I'm thinking
for i=1:4
fname = (sprintf('OutputFile_%d.txt',i));
fin = Coordinates{i};
time = Times{i};
fileID = fopen(fname);
for k = 1:n
coordString = '';
for j = 1:21
coordString = [coordString ',' num2str(fin(k,j))];
end
timeString = '';
for j = 1:24
timeString = [timeString time(k,j)];
end
stringToAdd = [coordString timeString];
end
fprintf(fileID,'%s',stringToAdd);
end
fclose(fileID)
end
You can do some fancy indexing to avoid some of those for loops, but I left them there for clarity. The best part about this method is that it is easy to debug cause you can see each string you are about to write.
There may be a way to do it with dlmwrite, but I honestly don't know it (I welcome anyone to set me straight :) )
Hope this helps!
Best Answer