left and right sides have a different number of elements.

조회 수: 1 (최근 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.

댓글을 달려면 로그인하십시오.

답변 (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