MATLAB: Wrong left and right assignment error

assignmentMATLAB

Hi there,
I have ellipsoids of different principal radii a b c and within these I attempt to quantify the number of smaller spheres with constant radii that I can fit into the ellipsoids and assess how the number of spheres changes with increasing ellipsoid axes.
The relationship of the counts and the size of the ellipsoids is as follows:
atom counts = 4/3*pi*a*b*c (2/0.0715)
I am still new to matlab and I am struggling to get a proper expression to assess this.
The code below gives the following error:
Unable to perform assignment because the left and right sides have a different number of elements.
a = [3.4995 3.098 2.737 1.9185 2.1555 2.6865 2.0295 2.3715 1.111 2.1575 1.93 1.6605 1.884 1.9795 3.0115 1.2425 2.569 1.8575 1.4275 1.427 2.2905];
b = [2.29 2.807 2.1635 1.6945 1.1335 2.0845 1.7195 2.013 0.9385 1.68 1.7545 0.9175 1.0685 1.029 2.392 0.986 2.1365 1.576 1.0705 1.104 1.882];
c =[2.035 1.295 2.035 1.295 1.295 1.295 1.295 1.295 0.74 1.48 0.925 0.925 1.665 1.11 1.665 0.74 2.035 1.295 0.74 0.555 1.665];
f_pi= 4.1888;
ucellatoms= 2/0.0715;
for n= 1:1:100
l(n) = n.*(a.*b.*c);
Mean_diam(n) =(n.*(a+b+c)./3);
atm_count = ucellatoms.*f_pi.*l;
plot (atm_count,l,'o')
nabc=l';
mean_d = Mean_diam';
atcounts=atm_count';
Ex = [nabc,atcounts];
plot(mean_d,atcounts, '*')
end

Best Answer

Your problem is that l(n) wants to place a single value into the array l in index n. But your a, b and c which you multiply with each other, are 1x21 arrays - as such the product of these is itself a 1x21 array. As such, you need to specify l (and Mean_diam as well) to be arrays themselves. The below will run, but I dont know if it will produce what you want it to :)
a = [3.4995 3.098 2.737 1.9185 2.1555 2.6865 2.0295 2.3715 1.111 2.1575 1.93 1.6605 1.884 1.9795 3.0115 1.2425 2.569 1.8575 1.4275 1.427 2.2905];
b = [2.29 2.807 2.1635 1.6945 1.1335 2.0845 1.7195 2.013 0.9385 1.68 1.7545 0.9175 1.0685 1.029 2.392 0.986 2.1365 1.576 1.0705 1.104 1.882];
c =[2.035 1.295 2.035 1.295 1.295 1.295 1.295 1.295 0.74 1.48 0.925 0.925 1.665 1.11 1.665 0.74 2.035 1.295 0.74 0.555 1.665];
f_pi= 4.1888;
ucellatoms= 2/0.0715;
for n= 1:1:100
l(:,n) = n.*(a.*b.*c);
Mean_diam(:,n) =(n.*(a+b+c)./3);
atm_count = ucellatoms.*f_pi.*l;
plot (atm_count,l,'o')
nabc=l';
mean_d = Mean_diam';
atcounts=atm_count';
Ex = [nabc,atcounts];
plot(mean_d,atcounts, '*')
end