像这样的东西适用于您的玩具箱:
l = length(P{1}(:)); m = size(P{1}, 1); n = size(P{1}, 2);
myfun = @(x) interp1([1 3], [P{1}(x) P{3}(x)], 2)
P{2} = reshape(arrayfun(myfun, 1:l), m, n);
更通用的代码(已验证!!)通常可以工作。您可以在一个 interp1 调用中指定要使用的插值类型:
[m, n] = size(P{1}); l = m*n;
avbl = find(not(cellfun('isempty', P)));
missing = find(cellfun('isempty', P));
extractor = @(k) cellfun(@(x, k) x(k), {P{avbl}}, cellmat(1, length(avbl), 1, 1, k))
myfun = @(x) interp1(avbl, extractor(x), missing)
intermediate = reshape(arrayfun(myfun, 1:l, 'UniformOutput', false), m, n);
ext2 = @(k) cellfun(@(p) p(k), intermediate);
P(missing) = arrayfun(ext2, 1:length(missing), 'UniformOutput', false);
如果你想让我解释一些部分,请告诉我。它基本上只是调用 cellfun 几次,然后重塑输出。