[Reddit Cross Post] Filtering results with small divergence

조회 수: 26 (최근 30일)
Toshiaki Takeuchi
Toshiaki Takeuchi 2025년 10월 15일 17:06
답변: Sam Chak 2025년 10월 17일 8:41
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!

채택된 답변

Sam Chak
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)
Qu = 1×3
100 200 205
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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)
204.9955 204.9792 99.9858 199.9985 205.0545
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)
204.9955 99.9858 199.9985
round(Q_solution)
ans = 1×3
205 100 200
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

제품


릴리스

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by