Create a vector using the even elements of another.
Afficher commentaires plus anciens
Hello,
I am trying to create a code to analyze Prandtl's lifting line thereom. The prompt calls for descritizing a wingspan into N nodes, where N must be an even number (100, 200, etc.). The nodes alternate "closed" and "open" (just for the sake of clarity). Each of the closed nodes are located at yj, where j = 1,3,5,...,N+1. The formula for finding the y position for every node along the wingspan is provided in the first for loop of my sample code.
Just to get my code running, I set N to 100, therefore there are 51 closed nodes. However, when I try to create a vector, yj, using only the odd elements from my y_pos vector, it alternates the correct value of yj and 0. I understand why it is doing this, but I'm at a loss on how to create a vector that only contains the odd elements from y_pos (i.e. a 51 element vector). Any help would be appreciated, thanks!
b = 10;
N = 100;
j = 1:2:N+1;
del_y = b/N;
for i = 1:1:N+1
y_pos(i) = -(b/2) + (i - 1).*del_y;
for ii = j
yj(ii) = -(b/2) + (ii - 1).*del_y;
end
end
Alternatively, this code just assigns y_pos(1) to every element yj
b = 10;
N = 100;
j = 1:2:N+1;
del_y = b/N;
for i = 1:1:N+1
y_pos(i) = -(b/2) + (i - 1).*del_y;
for ii = 1:1:(N/2)+1
yj(ii) = y_pos(i);
end
end
Réponse acceptée
Plus de réponses (1)
DGM
le 27 Avr 2022
If I understand the question correctly:
b = 10;
N = 100;
j = 1:2:N+1;
del_y = b/N;
i = 1:1:N+1;
y_pos = -(b/2) + (i - 1).*del_y; % all elements (101)
y_pos_odd = y_pos(j); % elements from odd indices (51)
Catégories
En savoir plus sur Behavior and Psychophysics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!