Matlab错误:两个输入数组的非单一维度必须彼此匹配
我有一个 1000x1 数组,其中我希望它根据 lambda 值 lam_packet 分成相等的部分,然后在每个部分中我将用随机二进制值替换 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
I have a 1000x1 array, in which i would like it to divide into equal parts based on a lambda value lam_packet, and then in each part i would replace 0 0 0 0 with radom binary values , but whenver i call this function i get an error
??? 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));
please any help would be very much appreciated.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
idx 是“strfind”调用的结果,它返回所有 [0 0 0 0] 字符串的位置。因此,它是一个任意大小的数组,数组的大小取决于“x1”的内容。因此,它可能不是长度 4。由于 bsxfun 的另一个输入是长度 4,因此您会收到错误。
idx is the result of the "strfind" call, which returns the locations of all the [0 0 0 0] strings. Thus, it is an arbitrary sized array, the size of the array depending on the contents of "x1". Thus, it is probably not length 4. Since the other input to bsxfun is length 4, you get the error.