[英]In an assignment A(I) = B, the number of elements in B and I must be the same
When running this code: 运行此代码时:
A(B<5) = C + (B-5)*5/10;
I'm getting the following error 我收到以下错误
In an assignment A(I) = B, the number of elements in B and I must be the same
Where A
, B
and C
are large matrices of same size (6399x6926). 其中A
, B
和C
是大小相同(6399x6926)的大型矩阵。 I could get it to work using a for
loop, but it took more time. 我可以使用for
循环使它工作,但是花费了更多时间。
The problem is that size of A(B<5)
will typically be smaller then size of A
. 问题在于A(B<5)
大小通常会小于A
大小。 Size of A(B<5)
will be equal to the number of elements of B
that obey condition B<5
. A(B<5)
将等于B
满足条件B<5
的元素的数量。
Example: 例:
B=[0 3 8 10]
A=[1 2 3 4]
A(B<5)=[1 2]
This is because only first two elements are less then 5. 这是因为只有前两个元素少于5。
Possibly, you wanted to do this: 您可能想这样做:
A(B<5) = C(B<5) + (B(B<5)-5)*5/10;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.