Difficulties using array indices with genetic algorithm

1 visualización (últimos 30 días)
Kim
Kim el 29 de Sept. de 2022
Respondida: Muskan el 5 de Sept. de 2023
Hello,
I am having problems using the genetic algorithm in Matlab.
I have simplified my example, but the final issue is that I want to do a parameter optimization of a geometry. To do this, I want to use the genetic algorithm to vary the parameters, for example "A" in this case. The geometry is generated from points in Matlab, saved and then calculated in FE software.
A = optimvar("A",'Type','integer',"LowerBound",1,"UpperBound",3);
nx = 100;
px = linspace(1,50,nx);
pyi = 5+sin(0.8*px);
py = 5+A+sin(0.8*px);
n=25;
t=(0:n)'*0.5*pi/n;
XYZI = cat(3,ones(n+1,1)*px,cos(t)*pyi,sin(t)*pyi);
XYZE = cat(3,ones(n+1,1)*px,cos(t)*py,sin(t)*py);
isbdri = false(size(XYZI,1),size(XYZI,2));
isbdri([1 end],:) = true;
isbdri(:,[1 end]) = true;
isbdre = false(size(XYZE,1),size(XYZE,2));
isbdre([1 end],:) = true;
isbdre(:,[1 end]) = true;
XYZI = reshape(XYZI,[],3);
n = size(XYZI,1);
XYZE = reshape(XYZE,[],3);
XYZ = [XYZI; XYZE];
index_i = XYZI(:,3) == 0;
E = XYZI(index_i,:);
E(:,3)=[];
index_e = XYZE(:,3) == 0;
F = XYZE(index_e,:);
F(:,3)=[];
Unfortunately, I am not getting anywhere with the indexing. I get the error "Array indices must either be real positive integers, logicals, character arrays, or strings".
As far as I understand, the optimization parameters are not assigned concrete values until the "solve" step. However, I need them already to be able to pass the point cloud to the FE program.
Can someone help me with this?
Many thanks in advance.

Respuestas (1)

Muskan
Muskan el 5 de Sept. de 2023
Hi Kim,
I understand that you are facing issues while using the genetic algorithm in MATLAB.
As per my understanding of the issue, the error comes in the following line;
F = XYZE(index_e,:);
The error occurs when you attempt to index into an array using indices that are not positive integers or logical values. For this case, index_e is a 2600×1 Linear “OptimizationEquality” array with properties:
-IndexNames
-Variables
Therefore, we cannot use this to to further index into another array.
Hence this is the reason you are getting the error "Array indices must either be real positive integers, logicals, character arrays, or strings".
You can further refer to the following answer for a better understanding of the issue:
I hope the above information helps resolve your query.
Thanks

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by