Wrong left and right assignment error

조회 수: 1 (최근 30일)
Arthur Moya
Arthur Moya 2019년 12월 9일
댓글: Jakob B. Nielsen 2019년 12월 9일
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

채택된 답변

Jakob B. Nielsen
Jakob B. Nielsen 2019년 12월 9일
편집: Jakob B. Nielsen 2019년 12월 9일
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
Arthur Moya
Arthur Moya 2019년 12월 9일
It works well thank you.
I am curious to understand what the l(:,n) syntex means.
Your response will be highly appreciated.
Kind regards
Arthur Moya
Jakob B. Nielsen
Jakob B. Nielsen 2019년 12월 9일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2019년 12월 9일
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?
  댓글 수: 1
Arthur Moya
Arthur Moya 2019년 12월 9일
편집: Arthur Moya 2019년 12월 9일
Thank you for your response.
I expect 'l' and 'Mean_diam' to be 100x1 vectors for every (a.*b.*c) to produce 21 curves with a 100 points.
My goal is to proportionally expand a b c using n from 1 to a 100 for every combination of a b c.
I didn't know how to best express the different values of a b and c such that an elementwise operation is done.
(I hope this makes some sense)
Kind regards,
Arthur Moya

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by