Azzera filtri
Azzera filtri

Difficulties using array indices with genetic algorithm

1 visualizzazione (ultimi 30 giorni)
Kim il 29 Set 2022
Risposto: Muskan il 5 Set 2023
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);
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);
index_i = XYZI(:,3) == 0;
E = XYZI(index_i,:);
index_e = XYZE(:,3) == 0;
F = XYZE(index_e,:);
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.

Risposte (1)

Muskan il 5 Set 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:
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.




Community Treasure Hunt

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

Start Hunting!

Translated by