嗨,我有以下 cellfun 操作:
b = cellfun(@(x) nansum(cross(u{1},x)),r,'UniformOutput',false);
其中 u 和 r 是向量。我想将叉积的结果乘以一个名为 I 的标量,但它必须在总和内。我可以简单地做:
b = cellfun(@(x) nansum(I.*cross(u{1},x)),r,'UniformOutput',false);
这行得通吗?
实际上只是尝试过并得到:
Matrix dimensions must agree.
Error in ==> cellcross>@(x)nansum(mag.*cross(u{1},x)) at 2
b = cellfun(@(x) nansum(mag.*cross(u{1},x)),r,'UniformOutput',false);
Error in ==> cellcross at 2
b = cellfun(@(x) nansum(mag.*cross(u{1},x)),r,'UniformOutput',false);
有什么建议么?
更新:
b = cellfun(@(x) nansum(bsxfun(@times, mag(:),cross(u{1},x))),r,'UniformOutput',false);