Это должно работать нормально:
% Generate sample data...
data = randi([0 99],2,randi([5 10],1));
event = 12;
% Call fopen with permission A (opens or creates a file for writing, appending data)...
fid = fopen('phase.dat','a');
% Write the event header...
fprintf(fid,'Event #%d %s\n',event,datestr(now(),'mmm dd yyyy'));
% Write the event data...
for k = 1:size(data,2)
fprintf(fid,'file #%d %02d %02d\n',k,data(1,k),data(2,k));
end
% Close the file handler...
fclose(fid);
Вот потенциальное содержимое файла после четырех запусков:
Event #11 May 01 2018
file #1 84 63
file #2 51 88
file #3 81 80
file #4 23 89
file #5 23 14
file #6 50 79
file #7 29 46
file #8 00 74
file #9 03 56
file #10 05 02
Event #12 May 01 2018
file #1 23 70
file #2 28 36
file #3 37 47
file #4 96 74
file #5 54 31
file #6 75 11
file #7 50 20
file #8 17 47
Event #13 May 01 2018
file #1 93 01
file #2 32 14
file #3 27 80
file #4 94 56
file #5 59 69
Event #14 May 01 2018
file #1 85 52
file #2 57 12
file #3 22 02
file #4 99 45
file #5 72 62
file #6 56 95
file #7 44 58
file #8 44 00
file #9 83 73
Вы можете настроить интервал в соответствии со своими потребностями, добавив \n
в конце fprintf
форматов вызовов.