0

我正在尝试对具有不同列数的数据集进行分析,但每次使用我的方程时我需要使用 3 列。我想使用数据集中的所有列(第一列和最后一列除外,因为它们不起作用)但我需要选择一个中心列、之前的列和之后的列。我需要实现这些方程:

lower_actual = lower_original - dark;
lower_avg = sum(lower_actual)/length(lower_actual);
lower_gain = lower_avg./lower_actual;

upper_actual = upper_original - dark;
upper_avg = sum(upper_actual)/length(upper_actual);
upper_gain = upper_avg./upper_actual;

middle_actual = middle_original - dark;

x1 = lower_actual;
x2 = middle_actual;
x3 = upper_actual;
y1 = lower_gain;
y3 = upper_gain;
y2 = (((x2-x1).*(y3-y1))./(x3-x1))+y1;
interpolate = y2.*middle_actual;

在这些方程中,变量与以下相关:

lower = column before
middle = center column
upper = column after
dark = first column in data set
4

2 回答 2

2

您可以使用HANKEL函数生成所有三个连续列的所有可能索引(第一列和最后一列除外):

例子:

>> X = rand(10,7);
>> idx = hankel((1:3)+1, 3+1:size(M,2)-1)
idx =
     2     3     4
     3     4     5
     4     5     6

每列按该顺序为您提供 X 列的一个组合的前/中/后的索引:

interpolate = zeros(size(X,1), size(idx,2));
for i=1:size(idx,2)
    ind = idx(:,i);
    xLower = X(:,ind(1));
    xMiddle = X(:,ind(2));
    xUpper = X(:,ind(3));

    %# perform calculations
    interpolate(:,i) = ...;
end
于 2012-08-01T18:10:37.673 回答
1

假设您在矩阵上工作M,例如

M = randn(10, 7);

只需遍历跳过第一个和最后一个的列。

interpolate = zeros(size(M, 1), size(M, 2) - 2);
dark = M(:, 1);
% Loop over the columns. Do not use the first and the last column as
% center columns.
for idx = 2 : size(M, 2) - 2
    lower_original = M(:, idx);
    middle_original = M(:, idx + 1);
    upper_original = M(:, idx + 2);

    % Your computations.
    lower_actual = lower_original - dark;
    lower_avg = mean(lower_actual);
    lower_gain = lower_avg./lower_actual;

    upper_actual = upper_original - dark;
    upper_avg = mean(upper_actual);
    upper_gain = upper_avg./upper_actual;

    middle_actual = middle_original - dark;

    x1 = lower_actual;
    x2 = middle_actual;
    x3 = upper_actual;
    y1 = lower_gain;
    y3 = upper_gain;
    y2 = (((x2-x1).*(y3-y1))./(x3-x1))+y1;

    interpolate(:, idx - 1) = y2.*middle_actual;
end

获取的最大列索引为size(M, 2) - 3 + 2 == size(M, 2) - 1,即最后一列将被跳过。

于 2012-08-01T17:49:34.077 回答