How to fix : Unable to perform assignment because the left and right sides have a different number of elements.
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to use particle swarm optimization to solve a problem of mine.
And i get following error:
Unable to perform assignment because the left and right sides have a
different number of elements.
This is the initial code:
function output= fun(X)
g(:,1)=[2;2]; R1=X(:,1); R3=X(:,2); R2= R3-g; n=X(:,3);
Br1=1.2;Br2=1.2;mu=4.*pi.*10.^-7;R4=35;
Length=70; L=2.*pi.*sqrt((R4.^2+R1.^2)./2);
x=(Br1.*Br2.*L.*(10^-6))/(4.*pi.*mu);
a=Length./n;
b=R2-R1;
d=R4-R3;
h=R3-R2;
c=-10:0.5:0;
F=0;
I feel there is an issue with how i have defined the variables.
댓글 수: 2
Dyuman Joshi
2023년 1월 18일
What is the full error and in which line does it occur?
Mention the code that is relevant to the line where the error occurs.
답변 (1개)
KSSV
2023년 1월 18일
This is a simple error, it occurs when you try to save more number of elements into an array than it is initialized for.
Ex:
A = zeros(1,3) ;
A(1) = rand ; % filling one element in one position
A(2) = rand(1,2) ; % filling two elements in one position; not correct so error
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle Swarm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!