left and right sides have a different number of elements.

2 ビュー (過去 30 日間)
Luca Re
Luca Re 2024 年 6 月 6 日
編集済み: Stephen23 2024 年 6 月 6 日
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.
Luca Re
Luca Re 2024 年 6 月 6 日
ok txk

サインインしてコメントする。

回答 (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 Center および File ExchangeStochastic 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