Wrong left and right assignment error
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Arthur Moya
il 9 Dic 2019
Commentato: Jakob B. Nielsen
il 9 Dic 2019
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
0 Commenti
Risposta accettata
Jakob B. Nielsen
il 9 Dic 2019
Modificato: Jakob B. Nielsen
il 9 Dic 2019
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
4 Commenti
Jakob B. Nielsen
il 9 Dic 2019
Well the first entry is row number, and l(:,1) = x simply means all rows in The first column. If you put a 2 row vector as x, The resulting l Will be a 2 by 1 array, and if your x is insteaf a 5000 row vector, your l Will be 5000 by 1. I hope that makes sense.
Più risposte (1)
Steven Lord
il 9 Dic 2019
for n= 1:1:100
l(n) = n.*(a.*b.*c);
When you execute that second line of code, n is a scalar (size 1-by-1.) The variables a, b, and c are 1-by-21 vectors. The result of evaluating n.*(a.*b.*c) is also 1-by-21. You're trying to stuff a 1-by-21 vector into one element of the variable l. That's not going to work; it doesn't fit.
What size do you want / expect the variables l and Mean_diam to be when this code finishes?
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!