布尔矩阵乘法在Matlab [英] Boolean Matrix Multiplication in Matlab

查看:3441
本文介绍了布尔矩阵乘法在Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Matlab的是否有一个布尔值(有时也称为逻辑或二进制)矩阵乘法功能?我专门谈论通常是由一个圆圈表示,在一个句点来表示布尔矩阵乘法:

  CIJ =(AI1&安培; B1J)|| (AI2&安培; B2J)|| (AI3&安培; B3J)|| ... || (AIK&安培; BKJ)

我有一个很难定位之一,我现在假设不存在。如果是这样的话,是有一个快速的方法写一个.m文件,将完成这项任务?

一个例子是:

  [1 1 1; [1 0 1; [1 1 1
 1 0 1; * circledot * 1 0 0; = 1 1 1
 1 0 0] 0​​ 1 0] 1 0 1]


解决方案

您可以只允许MATLAB来执行标准的矩阵乘法,并将结果转换为逻辑

  B1 = [1,1,1; 1,0,1; 1,0,0]
B2 = [1,0,1; 1,0,0; ​​0,1,0]
布特=(B1 * B2)大于0%或逻辑(B1 * B2)按纳坦的回答!布特=     1 1 1
     1 1 1
     1 0 1

然而,如果你要忠实履行布尔矩阵乘法运算符的逻辑与或操作,您可以使用 bsxfun 做和任何如下:

 回合=任何(bsxfun(@和,置换(B2,[3 2 1]),置换(B1,[1 3 2])),3);

这pretty以及混淆了过程,但它遵循的公式。

快速的测试数据: B1 =兰迪(2,M,N)-1; B2 =兰迪(2,N,M)-1;

Does Matlab have a Boolean (sometimes called logical or binary) matrix multiplication function? I'm specifically talking about what's usually denoted by a circle with a dot in it to denote Boolean matrix multiplication:

cij = (ai1 & b1j) || (ai2 & b2j) || (ai3 & b3j)|| ... || (aik & bkj)

I have had a hard time locating one and am now assuming one does not exist. If that is the case, is there a quick way to write a .m file that will accomplish this task?

An example would be:

[1 1 1;                [1 0 1;      [1 1 1
 1 0 1;   *circledot*   1 0 0;   =   1 1 1
 1 0 0]                 0 1 0]       1 0 1]

解决方案

You can just allow MATLAB to perform standard matrix multiplication and convert the result to logical:

b1 = [1,1,1;1,0,1;1,0,0]
b2 = [1,0,1;1,0,0;0,1,0]
bout = (b1*b2)>0 % or logical(b1*b2) as per natan's answer!

bout =

     1     1     1
     1     1     1
     1     0     1

However, if you want to faithfully perform the logical AND-OR operations of the Boolean matrix multiplication operator, you can do it with bsxfun and any as follows:

bout = any(bsxfun(@and,permute(b2,[3 2 1]),permute(b1,[1 3 2])),3);

That pretty well obfuscates the process, but it follows the formula.

Quick test data: b1 = randi(2,M,N)-1; b2 = randi(2,N,M)-1;.

这篇关于布尔矩阵乘法在Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆