Vectorization of an if condition with cirle function
Mostra commenti meno recenti
Hello,
I have a question regarding vectorization of loops.
In the case the value hT is changing depending on the position of the nodes (x-z plaine) with respect to two concentric circles.

It's not difficult to script this with a few loops, but this is extremly slow.
The value of hT, which is changing due to the geometric position is afterwards used in function TRB. The function TRB can be easy vectorized, but the I have the problem that the value of hT is not variet of the index variable j and ij.
Is it possible to make the code leaner, and faster with vectorization of the if elseif else condtion?
Here is the Structure of the slow loop script:
for i=[1 ny]
if i==1
for ij=2:1:nz-1
for j=2:1:nx-1
if ((j*dx-x0)^2+(ij*dz-z0)^2)<(RLN2^2)
hT=h(m,1);
TinfT=TinfTLN2N2;
elseif (((j*dx-x0)^2+(ij*dz-z0)^2)>((RLN2)^2))&&(((j*dx-x0)^2+(ij*dz-z0)^2)<=((RN2)^2))
hT=hTN2;
TinfT=TinfTLN2N2;
else
hT=hTAir;
TinfT=TinfTAir;
end
%
TRB(i,j,ij)=(hT*dx*dy+ BlaBla*To(1,j-1,ij)+);
end
end
else
The loop is cheking if the node is in the inner circle, between the inner and outer circle or outside of the circles and for each case the value of hT is different. Afterwards the TRB is calculated depending on the hT value.
Risposta accettata
Più risposte (1)
Steffen B.
il 22 Mar 2024
Modificato: Steffen B.
il 22 Mar 2024
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
