逻辑阵列 - 在分配A(I)= B,B中元素的个数,我必须是相同的 [英] Logical Arrays - In an assignment A(I) = B, the number of elements in B and I must be the same

查看:191
本文介绍了逻辑阵列 - 在分配A(I)= B,B中元素的个数,我必须是相同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个矩阵,A,B和C.当B大于A,我想与A.饱和的值它说,在我的元素数量(这是(B> A))必须中的相同答我下面检查元件的数目和它们是相同的。

 >> A = [5 5 5; 5 5 5; 5 5 5]。
>> B = [2 2 2; 2 2 2; 2 2 2];
>> C(B> A)= A
在分配A(I)= B,B中的元素,我的号码必须是相同的。>> numel(B> A)ANS =     9>> numel(A)ANS =     9>> numel(A> B)ANS =     9

这也是奇怪的是,这个作品。

 >> C(B< A)= AC =     5 5 5 5 5 5 5 5 5

我只是想通了......


  

    

C(B> A)= B(B> A)


  

C =

  5 5 5 5 5 5 5 5 5


解决方案

的原因是因为 B> A 永不满足,并产生空集。这会产生空矩阵( [] )。 B 的每一个元素实际上的 A 。因此,这等同于执行:

  C([])= A;

您正试图在矩阵分配 A 无处,然后这些尺寸不匹配。之所以 B< A 的工作原理是,因为 B 的每一个值小于 A ,所以分配 A的将在这里工作。一般情况下,你需要确保你正在访问的前pression右侧元素总数的必须等于在除权的左侧的相同数量的元素pression你想要的元素分配给

正如你在评论中提到,这样做的:

  C(B> A)= B(B> A)

将工作。这相当于这样做的:

  C([])= B([]);

...基本上,您正在执行什么都没有,所以这是一个安全的操作。没有值在 B 被分配到的位置在 A

正在访问

I have three matrices, A, B and C. When B is larger than A, I want to saturate the value with A. It says that the number of elements in I (which is (B > A)) must be the same as the number of elements in A. I checked below and they are the same.

>> A = [5 5 5; 5 5 5; 5 5 5];
>> B = [2 2 2; 2 2 2; 2 2 2];
>> C(B > A) = A
In an assignment  A(I) = B, the number of elements in B and I must be the same.

>> numel(B > A)

ans =

     9

>> numel(A)

ans =

     9

>> numel(A>B)

ans =

     9

It is also strange that this works.

>> C(B < A) = A

C =

     5     5     5     5     5     5     5     5     5

I just figured it out...

C(B>A) = B(B>A)

C =

 5     5     5     5     5     5     5     5     5

解决方案

The reason why is because B > A is never satisfied, and produces the empty set. This will produce the empty matrix ([]). Every element of B is actually smaller than A. As such, this is equivalent to performing:

C([]) = A;

You are trying to assign A to nowhere in the matrix, and those dimensions don't match. The reason why B < A works is because every value of B is less than A, and so the assignment of A will work here. In general, you need to make sure that the total number of elements you are accessing on the right side of the expression must equal the same number of elements on the left hand side of the expression you want to assign the elements to.

As you have mentioned in your comments, doing:

C(B > A) = B(B > A)

will work. This is equivalent to doing:

C([]) = B([]);

... essentially, you are performing nothing, so this is a safe operation. No values are being accessed in B are being assigned to locations in A.

这篇关于逻辑阵列 - 在分配A(I)= B,B中元素的个数,我必须是相同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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