[Reddit Cross Post] Filtering results with small divergence
조회 수: 26 (최근 30일)
이전 댓글 표시
Hello, I am currently working on a calculator for composite materials, due to the nature of composite materials, they have different mechanical properties regarding their respective angle when plied together. I am trying to filter the plies that have similar mechanical properties so I can extract them for my work. Example if Q1=100, Q2=100,1 Q3=100,5 Q4=200 Q5=205. The plies Q1,Q2,Q3 are similar and processing them in my further calculations creates an excessive computational strain that is not needed. How can I code the program to choose the Q3,Q4,Q5 values and discard the other ones? Any tip, video or anything else will be greatly appreciated. Thank you in advance!
댓글 수: 0
채택된 답변
Sam Chak
2025년 10월 17일 8:41
Are you looking for something like this
% Case 1
Q = [100 100 100 200 205];
Qu = unique(Q)
or something like this?
% Case 2
rng('default')
objfun = @(x) ((x - 100).*(x - 200).*(x - 205) + rand/1e4).^2;
options = optimoptions(@ga,'PopulationSize', 30, 'MaxGenerations', 60, 'Display', 'off');
for i = 1:5
xSol(i) = ga(objfun, 1, [], [], [], [], 0, 300, [], options);
end
disp(xSol)
Xsol = [100, 200, 205];
for j = 1:numel(xSol)
TF = isapprox(xSol(j), Xsol, AbsoluteTolerance=2e-2);
if sum(TF) == 1
Q(j) = xSol(j);
else
Q(j) = 0;
end
end
Q_solution = Q(Q ~= 0);
disp(Q_solution)
round(Q_solution)
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!