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-1-by-2.

5 visualizaciones (últimos 30 días)
I keep getting the above error when i run the below code. I have no clue on how to fix it. Its is pretty short code.
If anyone can assist, i will appreciate.
Thanks
%%
mo=4*10^-11; %initial particle mass in gCOD
Mx=7.2*10^-11; %maximum particle biomass
rho=32000; %maximum density of particles in gCOD/cubic metre of particles
Rp=(3*mo/(4*pi*rho))^1/3;
Rn=Rp;
%%
k=1*10^-6;
x1(1,1,1)=k;%initial pos AOB
x2=x1+1*10^-6; %initial pos Nitrobacter
x3=x2+1*10^-6; %initial pos Nitrospira
x4=x3+1*10^-6; %initial pos CMX
x5=x4+1*10^-6; %initial pos AMX
x6=x5+1*10^-6; %initial pos het
sum1(1,1,1)=0.0;
sum2=0.0;
cell=0.8*10^-6;
r=0:7.5;
l=0:14;
c=0:109.8232;
deltaxj(1,1,1)=k;
x1New(1,1,1)=x1;
for i=1:length(r)
for ii=1:length(l)
for iii=1:length(c)
dn(i,ii,iii)=sum1+(x1-x1New)^2;
deltaxj(i,ii,iii)=sum1+(x1-x1New)*(k.*(Rn+Rp)-dn)./dn;
x1New(i,ii,iii)=x1-deltaxj;
end
end
end
  5 comentarios
Rik
Rik el 16 de Abr. de 2021
The contents of your loop don't depend on the loop variables (unless one of them is a function). Is that the intention?
KIPROTICH KOSGEY
KIPROTICH KOSGEY el 19 de Abr. de 2021
r , l and c are interdependent.
r represents z in the cartesian system, l represents x and c represent y.
The aim is to model bacterial colonisation of a wedge-shaped void. I am yet to introduce other functions.

Iniciar sesión para comentar.

Respuesta aceptada

Daniel Pollard
Daniel Pollard el 16 de Abr. de 2021
I haven't run it, but I think your code will error on the line
deltaxj(i,ii,iii)=sum1+(x1-x1New)*(k.*(Rn+Rp)-dn)./dn;
because deltaxj(i,ii,iii) is a number, so has one element, and dn is an array which grows with every iteration. You can't assign an array element to be equal to an array.
I suspect you intended
deltaxj(i,ii,iii)=sum1+(x1-x1New)*(k.*(Rn+Rp)-dn(i,ii,iii))./dn(i,ii,iii);
As a side note, please choose better names for your loop indices. Firstly, i is a bad variable name because it already has a built-in value, and secondly, it's difficult to tell at a glance what the difference between (ii,iii) and (iii,i) is (for example). If you really need to use that many nested loops (rather than vectorising your code), I'd suggest using k1, k2, k3, or similar.
  3 comentarios
Daniel Pollard
Daniel Pollard el 16 de Abr. de 2021
Well x1new is a number, so trying to index it like x1new(i,ii,iii) will always return an error as soon as i, ii or iii are anything other than 1, which happens when the iii loop iterates around and tries to work with iii=2. The line with the error isn't even in the code you posted, it was right before so I had no reason to correct it for you!
Glad you found the solution in the end though.
KIPROTICH KOSGEY
KIPROTICH KOSGEY el 16 de Abr. de 2021
Thanks @Daniel Pollard, I am still improving on what @Rik suggested, hope it will work when i include more parameters on the code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by