left and right sides have a different number of elements.

2 次查看(过去 30 天)
Hi, i've this problem
i is a logical 5995x1... price and bubu have equal size
load('matlab_3Variable.mat');
price(i)=bubu;
Unable to perform assignment because the left and right sides have a different number of elements.
  6 个评论
Torsten
Torsten 2024-6-6
编辑:Torsten 2024-6-6
load('matlab_3Variable.mat');
price(i)=bubu(i)
price = 5995x1
1.0e+03 * 1.4645 1.4645 1.4645 1.4645 1.4645 1.4645 1.4645 1.4645 1.4645 1.4538
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
would set the values of price to the values of bubu for which i has logical 1 and leave the other values of price unchanged.
But if it's what you want - we don't know.

请先登录,再进行评论。

回答(1 个)

Matlab Pro
Matlab Pro 2024-6-6
This is simple - since the 'i' is a logical indexing vector and is not all 'true'
length(find(i)) % == 5948
ans = 0
Thus: price(i) is a [5948x1] matrix and you want it to hold "bubu" which is 5995 matrix --> impossible
This - can be easliy fixed (if this is your requested outcome) like that;
price(i)=bubu(i);
Unrecognized function or variable 'bubu'.
  2 个评论
Luca Re
Luca Re 2024-6-6
hi, it's not correct because "price" and "bubu" can to have to different size
Stephen23
Stephen23 2024-6-6
编辑:Stephen23 2024-6-6
"it's not correct because "price" and "bubu" can to have to different size"
They do not need to be the same sizes:
A = rand(2,3)
A = 2x3
0.3686 0.1659 0.7087 0.4115 0.2469 0.8034
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = rand(4,5)
B = 4x5
0.3748 0.3379 0.6675 0.3304 0.4606 0.1202 0.2557 0.4158 0.0023 0.7938 0.1573 0.9340 0.4140 0.4896 0.3321 0.8504 0.4113 0.6661 0.6588 0.1033
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
X = [true,false,true,false,true]
X = 1x5 logical array
1 0 1 0 1
A(X) = B(X)
A = 2x3
0.3748 0.1573 0.3379 0.4115 0.2469 0.8034
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
What is relevant is how many elements on the RHS you are trying to allocate to the LHS.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Stochastic Differential Equation (SDE) Models 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by