Как объединить два столбца данных в один файл.Этот код должен создать новый файл с двумя столбцами.Несмотря на то, что он выдает 2 столбца, но данные не верны, когда все данные a
были записаны первыми, а затем данные duration
fid=fopen('data1.txt');
A =textscan(fid,'%f%f%f%f%f%f%f%f%f%f%f%f'); % read a txt file
in = cell2mat(A); %change to matrix
fclose(fid);
index = find(in(2:end,2) == in(1:end-1,2)) + 1; %condition 1
duration(index)= in(index,4) - in(index-1,4);
a(index)=in(index,2);
fid = fopen('test.txt','wt');
format short g;
fprintf(fid,'%g\t%g\n',a,duration);
fclose(fid);
РЕДАКТИРОВАНИЕ: Формат вывода был таким, как показано ниже -
318684 24 % 318684 I don't know where this number come from, not from the input
24 24 % this is the a output
24 24
1.1 1.08 % this is the duration output
2.1 0.77
Предполагаемая мощность
24 1.1
24 1.08
24 2.1
24 0.77
1.3 1.8