フィルターのクリア

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-15. - can't find what the problem is

5 ビュー (過去 30 日間)
I keep getting this error, but I have no idea what's causing it.
Using the step button brings up nothing until the very end when it tries to finish.
all of the X's,Z's,Y's within Fd are 15x1 with positive integers
Any ideas as to what's causing this?
Fd=zeros(cap, cap, cap,term); %here is the original matrix I created cap=15 and term=20
...
for tt=19:-1:1
for i=1:cap
for j=1:cap
for k=1:cap
... %for brevity's sake I've ommitted some stuff here that doesn't seem to be causing issues
Fd(i,j,k,tt)= b*(...
m1*(...
p(y(j),z1(k))*(n1*Fd(xp(i),zp(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zpp(j),y(k),tt+1))+...
(1-p(y(j),z1(k)))*(n2*Fd(xp(i),z1(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z1(j),ygg(k),tt+1)))+...
(1-m1)*(...
p2(y(j),z2(k))*(n1*Fd(xp(i),zd(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zdd(j),y(k),tt+1))+...
(1-p2(y(j),z2(k)))*(n2*Fd(xp(i),z2(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z2(j),ygg(k),tt+1))...
))+...
(1-b)*( ...
m2*(...
p(y1(j),z(k))*(n1*Fd(xp(i),zg(j),y1(k),tt+1) + (1-n1)*Fd(xpp(i) ,zgg(j),y1(k),tt+1))+ ...
(1-p(y1(j),z(k)))*(n2*Fd(xp(i),z(j),yp(k),tt+1) + (1-n2)*Fd(xpp(i) ,z(j),ypp(k),tt+1)))+ ...
(1-m2)*(p(y2(j),z(k))*(n1*Fd(xp(i),zg(j),y2(k),tt+1) + (1-n1)*Fd(xpp(i),zgg(j),y2(k),tt+1))+...
(1-p(y2(j),z(k)))*(n2*Fd(xp(i),z(j),yd(k),tt+1) + (1-n2)*Fd(xpp(i),z(j),ydd(k),tt+1))));
If more code is required, I can certainly provide
  2 件のコメント
Torsten
Torsten 2024 年 4 月 19 日
If you don't know which variable on the right-hand side is 15x1, you will have to output their sizes within the loop.
But I'm almost sure that having Fd on both sides of the equation will cause problems.
Kitt
Kitt 2024 年 4 月 20 日
So you think it's because I have Fd on both sides? I'm brand spanking new to matlab and I'm trying to run a stochastic dynamic program. It's been a steep learning curve.

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

回答 (1 件)

Voss
Voss 2024 年 4 月 19 日
編集済み: Voss 2024 年 4 月 19 日
Assuming that b, m1, m2, n1, and n2 are scalars, the code runs ok. (Also assuming that the integers stored in the x, y, z variables do not exceed 15; if they did you'd get a different error.) If any of b, m1, m2, n1, or n2 are not scalars, you might get the error you saw.
Running with scalars works:
cap = 15;
term = 20;
b = 0.8;
m1 = 0.7;
m2 = 0.6;
n1 = 0.5;
n2 = 0.4;
xp = randi(cap,15,1);
xpp = randi(cap,15,1);
y = randi(cap,15,1);
y1 = randi(cap,15,1);
y2 = randi(cap,15,1);
yd = randi(cap,15,1);
ydd = randi(cap,15,1);
yg = randi(cap,15,1);
ygg = randi(cap,15,1);
yp = randi(cap,15,1);
ypp = randi(cap,15,1);
z = randi(cap,15,1);
z1 = randi(cap,15,1);
z2 = randi(cap,15,1);
zd = randi(cap,15,1);
zdd = randi(cap,15,1);
zg = randi(cap,15,1);
zgg = randi(cap,15,1);
zp = randi(cap,15,1);
zpp = randi(cap,15,1);
p = rand(cap,cap);
p2 = rand(cap,cap);
Fd=zeros(cap, cap, cap, term);
for tt=term-1:-1:1
for i=1:cap
for j=1:cap
for k=1:cap
Fd(i,j,k,tt) = ...
b*( ...
m1*( ...
p(y(j),z1(k))*(n1*Fd(xp(i),zp(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zpp(j),y(k),tt+1))+ ...
(1-p(y(j),z1(k)))*(n2*Fd(xp(i),z1(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z1(j),ygg(k),tt+1)))+ ...
(1-m1)*( ...
p2(y(j),z2(k))*(n1*Fd(xp(i),zd(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zdd(j),y(k),tt+1))+ ...
(1-p2(y(j),z2(k)))*(n2*Fd(xp(i),z2(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z2(j),ygg(k),tt+1)) ...
))+ ...
(1-b)*( ...
m2*( ...
p(y1(j),z(k))*(n1*Fd(xp(i),zg(j),y1(k),tt+1) + (1-n1)*Fd(xpp(i) ,zgg(j),y1(k),tt+1))+ ...
(1-p(y1(j),z(k)))*(n2*Fd(xp(i),z(j),yp(k),tt+1) + (1-n2)*Fd(xpp(i) ,z(j),ypp(k),tt+1)))+ ...
(1-m2)*( ...
p(y2(j),z(k))*(n1*Fd(xp(i),zg(j),y2(k),tt+1) + (1-n1)*Fd(xpp(i),zgg(j),y2(k),tt+1))+ ...
(1-p(y2(j),z(k)))*(n2*Fd(xp(i),z(j),yd(k),tt+1) + (1-n2)*Fd(xpp(i),z(j),ydd(k),tt+1)) ...
));
end
end
end
end
any(Fd,'all')
ans = logical
0
Running with b, for instance, of size 15x1 generates the error you got:
b = 0.8*ones(cap,1);
Fd=zeros(cap, cap, cap, term);
for tt=term-1:-1:1
for i=1:cap
for j=1:cap
for k=1:cap
Fd(i,j,k,tt) = ...
b*( ...
m1*( ...
p(y(j),z1(k))*(n1*Fd(xp(i),zp(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zpp(j),y(k),tt+1))+ ...
(1-p(y(j),z1(k)))*(n2*Fd(xp(i),z1(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z1(j),ygg(k),tt+1)))+ ...
(1-m1)*( ...
p2(y(j),z2(k))*(n1*Fd(xp(i),zd(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zdd(j),y(k),tt+1))+ ...
(1-p2(y(j),z2(k)))*(n2*Fd(xp(i),z2(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z2(j),ygg(k),tt+1)) ...
))+ ...
(1-b)*( ...
m2*( ...
p(y1(j),z(k))*(n1*Fd(xp(i),zg(j),y1(k),tt+1) + (1-n1)*Fd(xpp(i) ,zgg(j),y1(k),tt+1))+ ...
(1-p(y1(j),z(k)))*(n2*Fd(xp(i),z(j),yp(k),tt+1) + (1-n2)*Fd(xpp(i) ,z(j),ypp(k),tt+1)))+ ...
(1-m2)*( ...
p(y2(j),z(k))*(n1*Fd(xp(i),zg(j),y2(k),tt+1) + (1-n1)*Fd(xpp(i),zgg(j),y2(k),tt+1))+ ...
(1-p(y2(j),z(k)))*(n2*Fd(xp(i),z(j),yd(k),tt+1) + (1-n2)*Fd(xpp(i),z(j),ydd(k),tt+1)) ...
));
end
end
end
end
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 15-by-1.
It may be that one or more of b, m1, m2, n1, and n2 has its value changed inadvertently to a non-scalar value.
You can try
dbstop if error
and when the code stops check the variables to figure out what's causing the problem.
  4 件のコメント
Torsten
Torsten 2024 年 4 月 20 日
編集済み: Torsten 2024 年 4 月 20 日
Yes, but all these equations are implicit in the Fd values. Inserting 0 when the corresponding value for Fd is not yet determined doesn't make sense. All these equations in the loop had to be arranged to one big linear system with the Fd's as unknowns.
Voss
Voss 2024 年 4 月 20 日
I'm sure you're right. I was just trying to reproduce the error.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by