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.
Ältere Kommentare anzeigen
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 Kommentare
Daniel Pollard
am 16 Apr. 2021
If you format your code properly, it'll be much easier to read, and then easier to help you. What line does the error occur on? What were you expecting the code to output?
Rik
am 16 Apr. 2021
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
You should use the debugger to step through your code and see what line changes the size or data type of your variables in an unexpected manner.
You are also dynamically growing variables, which becomes slow very fast. Pre-allocate array you can determine the size for:
dn=zeros(numel(r),numel(l),numel(c));
deltaxj=zeros(size(dn));
x1New=zerso(size(dn));
for i=1:size(dn,1)
for ii=1:size(dn,2)
for iii=1:size(dn,3)
You should avoid length. Use numel or size instead. You should also avoid l and I variable names. Can you spot the differences at a glance?
Il1
KIPROTICH KOSGEY
am 16 Apr. 2021
Rik
am 16 Apr. 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
am 19 Apr. 2021
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!