Difficulties using array indices with genetic algorithm

2 次查看(过去 30 天)
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.

回答(1 个)

Muskan
Muskan 2023-9-5
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

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by