Matlab错误:两个输入数组的非单一维度必须彼此匹配

发布于 2024-12-18 07:17:36 字数 849 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴随着你 2024-12-25 07:17:36

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文