我有数据这样的数据文件:
0 -7.09381e-10 7.88112e-09
1 -3.365e-09 3.96397e-08
2 -1.74014e-09 1.3715e-08
3 -6.79327e-10 4.74787e-09
4 -1.92799e-10 1.56609e-09
5 6.53422e-11 5.09169e-10
6 5.21863e-11 1.73983e-10
7 5.64361e-11 6.29614e-11
0 -9.44027e-10 8.14559e-09
1 -2.02866e-09 4.29019e-08
2 -2.2109e-10 1.57419e-08
3 4.55366e-11 5.97503e-09
4 1.70868e-10 2.28134e-09
5 1.90134e-10 8.52557e-10
6 4.4223e-11 3.2142e-10
7 7.2096e-12 1.22047e-10
此序列中的另外100组数据一个接一个。第一列索引是时间索引。我折叠数据,然后使用以下matlab代码计算第2列和第3列的比率:
data_jknife =dlmread('datafile.txt',' ');
metadata = data_jknife(:,1); % a bidimensional array data_jknife, and want to access all its elements on the first column
data1 = data_jknife(:,2);%accessing all the elements on the second clomun
data2 = data_jknife(:,3);
groupedMetaData = arrayfun(@(x) metadata(x:4:end), 1:4 ,'UniformOutput',false );
groupedData1 = arrayfun(@(x) data1(x:4:end), 1:4 ,'UniformOutput',false ); %grouping data from the second column
groupedData2 = arrayfun(@(x) data2(x:4:end), 1:4 ,'UniformOutput',false );
flippedData1 = fliplr(groupedData1);
flippedData1 = flippedData1(1:2);
foldedData1 = cellfun(@(x,y) mean([x y],2), flippedData1 ,groupedData1(1:numel(flippedData1)),'UniformOutput',false);
flippedData2 = fliplr(groupedData2);
flippedData2 = flippedData2(1:4);
foldedData2 = cellfun(@(x,y) mean([x y],2), flippedData2 ,groupedData2(1:numel(flippedData2)),'UniformOutput',false);
foldedData = cellfun(@rdivide, foldedData1, foldedData2,'UniformOutput',false);
所以foldingData的输出应该是这样的:
0 R(0)
1 R(1)
0 R'(0)
1 R'(1)
2 R'(2)
其中R是第二列除以相应时间片的折叠数据的第3列。现在我想以上述格式将输出写入文件中。但我不知道该怎么做。有人可以帮帮我吗?提前致谢。所以这是操作的数值 好。因此,对于数据集的第一个序列,折叠就像这样: 第二列元素(我取t = 0,3,4,7数据的平均值)
((-7.09381*10^-10) + (-6.79327*10^-10) + (-1.92799*10^-10) +
(5.64361*10^-11))/4 =
-3.81268*10^-10
第3栏元素:
((7.88112*10^-09) + (4.74787*10^-09) + (1.56609*10^-09) + (6.29614*10^-11))/4 =
3.56451*10^-9
然后我取t = 1,2,5,7数据的平均值。所以第二列是:
((-3.365*10^-09) + (-1.74014*10^-09) + (6.53422*10^-11) + (5.64361*10^-11))/4=
-1.24584*10^-9
第3栏是:
((3.96397*10^-08) + (1.3715*10^-08) + (5.09169*10^-10) + (1.73983*10^-10))/4=
1.35095*10^-8
因此,对于第一个数据序列,输出为:
R0 = (-3.81267725`*^-10)/(3.5645103500000007`*^-9) = -0.106962
R1 = (-1.245840425`*^-9)/(1.35095*10^-8) = -0.0922198
因此第一个序列的所需输出是:
0 -0.106962
1 -0.0922198
答案 0 :(得分:0)
<强>代码强>
%%// input_filepath and output_filepath are the paths to the input and
%%// output files
d1 = dlmread(input_filepath,' ')
t1 = permute(reshape(d1',24,[]),[1 3 2]) %%//'
d1 = permute(reshape(t1,3,8,[]),[2 1 3])
d2 = d1([0 3 4 7]+1,[2 3],:)
d22 = d1([1 2 5 7]+1,[2 3],:)
t1 = [mean(d2) ; mean(d22)]
t2 = t1(:,1,:)./t1(:,2,:)
out = [repmat([0:size(t1,1)-1]',size(t2,3),1) t2(:)] %%//'
datacell = cellstr(num2str(out))
fid1 = fopen(output_filepath,'w');
for k = 1:size(datacell,1)
fprintf(fid1,'%s\n',datacell{k,:});
end
fclose(fid1);