How to fix : Unable to perform assignment because the left and right sides have a different number of elements.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Dyuman Joshi
el 18 de En. de 2023
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.
Respuestas (1)
KSSV
el 18 de En. de 2023
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 comentarios
Ver también
Categorías
Más información sobre Particle Swarm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!