简体   繁体   English

bsxfun:所连接矩阵的维数不一致

[英]bsxfun: Dimensions of matrices being concatenated are not consistent

Any one knows where the error is? 有人知道错误在哪里吗? Many thanks! 非常感谢!

beta=randn(50,1);
bsxfun(@(x1,x2) max([x1 x2 x1+x2]), beta, beta')

error message: 错误信息:

Error using horzcat 使用Horzcat时出错
Dimensions of matrices being concatenated are not consistent. 串联的矩阵尺寸不一致。
Error in @(x1,x2)max([x1,x2,x1+x2]) @(x1,x2)max([x1,x2,x1 + x2])中的错误

I'm not 100% sure what you want to achieve, but the error is in the transposition of beta as third argument of bsxfun ; 我不是100%不确定要实现什么,但是错误在于将betabsxfun第三个参数; it works like this: 它是这样的:

beta=randn(50,1); 
bsxfun(@(x1,x2) max([x1 x2 x1+x2]), beta, beta)

The second and third argument of bsxfun needs to be of the same size to apply element-wise binary operations to it. bsxfun的第二个和第三个参数的大小必须相同,才能对其应用按元素的二进制运算。

Edit: From the manual ( http://www.mathworks.de/de/help/matlab/ref/bsxfun.html ): 编辑:从手册( http://www.mathworks.de/de/help/matlab/ref/bsxfun.html ):

fun can also be a handle to any binary element-wise function not listed above. fun也可以是上面未列出的任何二进制按元素函数的句柄。 A binary element-wise function of the form C = fun(A,B) accepts arrays A and B of arbitrary, but equal size and returns output of the same size. 形式为C = fun(A,B)的二进制按元素函数接受任意但大小相等的数组A和B,并返回相同大小的输出。 Each element in the output array C is the result of an operation on the corresponding elements of A and B only. 输出数组C中的每个元素仅是对A和B的相应元素进行运算的结果。

EDIT2 : Is this, what you want? EDIT2 :这是您想要的吗?

A = rand(1,50);
[x, y] = ndgrid(1:length(A), 1:length(A));
idc = [x(:) y(:)];
allMin = min([A(idc(:,1)) A(idc(:,2)) A(idc(:,1))+A(idc(:,2))]);

First, with the second and third code-line I generate all possible combinations of indices (all pairs i / j ), eg: If A has 3 entries, idc would look like: 首先,使用第二和第三条代码行生成索引的所有可能组合(所有对i / j ),例如:如果A有3个条目,则idc看起来像:

1 1
1 2 
1 3
2 1
2 2
2 3
3 1 
3 2
3 3

and then I'm building up a vector containing the value A(i) , A(j) and A(i)+A(j) for each row of entries ( i , j ) and getting the min of it. 然后我为每个条目行( ij )建立一个包含值A(i)A(j)A(i)+A(j)的向量,并获取其min

Here's what I got (using two max in bsxfun ) 这就是我得到的(在bsxfun使用两个max

beta = randn(50,1); 
res = bsxfun(@(x,y) max( x, max(y, x+y) ), beta, beta');

Verifying using repmat 使用repmat验证

tmp = max( cat(3, repmat(beta,[1 50]), repmat(beta',[50 1]), ...
                  repmat(beta,[1 50])+ repmat(beta',[50 1]) ), [], 3);
isequal( tmp, res )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 matlab连接的矩阵尺寸不一致 - matlab Dimensions of matrices being concatenated are not consistent 使用垂直时发生错误:串联的矩阵尺寸不一致 - Error using vertical: Dimensions of matrices being concatenated are not consistent 如何解决:使用horzcat时发生错误所连接矩阵的维数不一致 - How to solve: Error using horzcat Dimensions of matrices being concatenated are not consistent 使用CAT的matlab错误,所连接矩阵的维数不一致 - matlab error using CAT, Dimensions of matrices being concatenated are not consistent 使用带有字符的数组时,要级联的矩阵的维数不一致 - Dimensions of matrices being concatenated are not consistent using array with characters 在1x6802 double和6802x1 double数据矩阵中,级联矩阵的尺寸不一致 - Dimensions of matrices being concatenated are not consistent in 1x6802 double and 6802x1 double data matrix 我如何处理“使用vertcat的错误连接矩阵的尺寸在Matlab中不一致”? - How do i handle “Error using vertcat Dimensions of matrices being concatenated are not consistent” in Matlab? 我的代码运行,有时会出现错误“使用horzcat时出错,所连接的矩阵维数不一致。” - My code runs then sometimes it has error “Error using horzcat Dimensions of matrices being concatenated are not consistent.” sequenceInputLayer() 被连接的数组的维度不一致 - sequenceInputLayer() Dimensions of arrays being concatenated are not consistent Matlab代码崩溃并给出错误:所连接矩阵的维数不一致 - Matlab code crashes and gives error: Dimension of matrices being concatenated are not consistent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM