Matlab错误:两个输入数组的非单例维度必须相互匹配

时间:2011-11-25 14:57:43

标签: matlab dimension mismatch bsxfun

我有一个1000x1数组,其中我希望它基于lambda值lam_packet分成相等的部分,然后在每个部分我将用radom二进制值替换0 0 0 0,但是当我调用这个函数时我收到错误

??? Error using ==> bsxfun
Non-singleton dimensions of the two input arrays must match each other.

Error in ==> imputation at 11
idx = bsxfun(@plus, idx', (0:3));

请非常感谢任何帮助。

function [ xxx ] = imputation(x,lam_packet,noframes)
x1=x(:,1:-1:1).';
for i=1:lam_packet:noframes
%# starting locations of four-consecutive zeros
idx= strfind(x1(i), [0 0 0 0]);

%# random binary numbers (rows) used to replace the consecutive zeros
n = dec2bin(randi([0 8],[numel(idx) 1]),4) - '0';

%# linear indices corresponding to the consecutive-zeros
idx = bsxfun(@plus, idx', (0:3));

%'# replace the 4-zeros
xx = x1;
xx(idx(:)) = n(:);
end
xxx = xx(1:-1:1,:).';

end
enter code here

1 个答案:

答案 0 :(得分:0)

idx是“strfind”调用的结果,它返回所有[0 0 0 0]字符串的位置。因此,它是一个任意大小的数组,数组的大小取决于“x1”的内容。因此,它可能不是长度4.由于bsxfun的另一个输入是长度4,你会得到错误。